Cas
Cas

Reputation: 758

cPanel API - Execution not permitted inside of webmail (api2)

I'm working on an application to manage cPanel accounts from a mobile app, but first I am making a proof of concept as a simple windows forms application. The users should be able to authenticate using their username and password.

However, it doesn't matter what action I try to perform, I always get the following response:

<Root>
  <cpanelresult>
    <apiversion>2</apiversion>
    <error>Execution of Email::addpop is not permitted inside of webmail (api2)</error>
    <func>addpop</func>
    <data>
      <reason>Execution of Email::addpop is not permitted inside of webmail (api2)</reason>
      <result>0</result>
    </data>
    <module>Email</module>
  </cpanelresult>
</Root>

This error occurs for every function I have tried. The cPanel account has all features in their feature list.

I use the following code to call the API:

Form

Communication com = new Communication();

string result = com.SendRequest("Email", "addpop",
                "&domain ='apitest.DOMAIN.nl'&email='user'&password='12345luggage'&quota='500'");

txtOutput.Text = result;

Communication class

public string SendRequest(string module, string function, string extra = "")
{
    try
    {
        var httpWebRequest =
            (HttpWebRequest) WebRequest.Create(Settings.Default.Server +
                                                string.Format(
                                                    "/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module={0}&cpanel_jsonapi_func={1}{2}",
                                                    module, function, extra));
        httpWebRequest.Accept = "*/*";
        httpWebRequest.Method = "GET";

        string credentials = (username + ":" + password).Base64Encode();

        httpWebRequest.Headers.Add("Authorization: Basic " + credentials);

        var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();



        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            string answer = streamReader.ReadToEnd();
            XNode node = JsonConvert.DeserializeXNode(answer, "Root");

            return node.ToString();
        }
    }
    catch (WebException ex)
    {
        switch (ex.Status)
        {
            case WebExceptionStatus.ProtocolError:
                return ((HttpWebResponse) ex.Response).StatusCode.ToString();
            case WebExceptionStatus.NameResolutionFailure:
                return "Could not find specified domain: " +
                        ex.Status.ToString();
        }
    }
    return null;
}

Any help would be very much appreciated.

Upvotes: 0

Views: 256

Answers (1)

Cas
Cas

Reputation: 758

The issue was caused by using the wrong port. Even though I thought I checked the port multiple times I did actually connect to the webmail port (2087) instead of the cPanel port (2083)

Simply modifying the port in the connection to 2083 solved the issue.

Upvotes: 0

Related Questions