A simple C# wrapper for accessing cPanel APIs.
Install-Package cPanelSharp
First, we declare a cPanelClient
with required params.
To connect to a cPanel instance, the required parameters are:
- username
- hostname (will be something like
*.sgcpanel.com
) - password
also the cPanel
argument needs to be set to true
.
var client = new cPanelClient("<username>", "<hostname>", password: "<password>", cPanel: true);
Look up the cPanel API 2 and find the call you want to make.
Consider that you want to get the list of email accounts. You'll see Email::listpops
on the title. Everything to the left of ::
forms the module
and everything to the right of ::
forms the function
. With this we get:
- Module:
Email
- Function:
listpops
Now, we can call the Api2
function with the required parameters
var response = client.Api2("Email", "listpops");
Parameters can be specified using an object. Email::listpops
takes an optional regex
param to search by. Lets pass that to the function in the form of an object
var response = client.Api2("Email", "listpops", new
{
regex = "foo"
});
All credits to https://github.com/vexxhost/python-cpanelapi