Using Web API

Web API reference

Introduction

This API allows applications to communicate with backend code of WebMail Pro 8. You can create your custom frontend which would interact with WebMail Pro 8 backend via Web API. Note that the application which uses Web API doesn't have to be written in JavaScript, it doesn't even have to be a web application, you can use this API in mobile, desktop and server applications as well.

Note that you can also use PHP API to integrate WebMail Pro 8 with your application, assuming both are installed on the same server.

Getting started

Below, please find an example of the code written in Javascript or C#, which performs a typical Web API request.

javascript

$.ajax({
    url: 'index.php?/Api/',
    type: 'POST',
    async: true,
    dataType: 'json',
    data: {
        Module: 'Core',
        Method: 'GetSettings'
    },
    success: function (oResponse) {
        if (oResponse)
        {
            var oSettings = oResponse.Result;
            console.log('oSettings', oSettings);
        }
    }
});

C#

string url = "https://pro8.afterlogic.com/?/Api/";
using (var client = new WebClient())
{
    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
    string strData = "Module=Core&Method=GetSettings";
    strData = client.UploadString(url, strData);
    Console.WriteLine(strData);
}

The following points are important in this regard:

  1. The entry point for making all the Web API calls is WebMail Pro 8 installation URL with /?/Api/ appended.
  1. All the Web API calls are to be performed using POST;
  1. Installation contains a number of modules, therefore each request is processed by a specific module specified in POST data. Name of the method in this module is specified there as well.

Authentication

Some methods will only return useful data if you authenticate to an account. That can be done by sending Login request to Core module:

javascript

$.ajax({
    url: 'index.php?/Api/',
    type: 'POST',
    async: true,
    dataType: 'json',
    data: {
        Module: 'Core',
        Method: 'Login',
        Parameters: '{"Login":"login_value","Password":"pass_value"}'
    },
    success: function (oResponse) {
        if (oResponse && oResponse.Result)
        {
            var sAuthToken = oResponse.Result.AuthToken;
            console.log('sAuthToken', sAuthToken);
        }
    }
});

C#

string url = "https://pro8.afterlogic.com/?/Api/";
using (var client = new WebClient())
{
        client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        string strData = "Module=StandardAuth&Method=Login&Parameters{Login:\"login_value\",Password:\"password_value\"}";
        strData = client.UploadString(url, strData);
        Console.WriteLine(strData);
}

Successful request will result in JSON-formatted response of the following kind:

{
    Module: 'Core',
    Method: 'Login',
    Result: {
        AuthToken: 'token_value'
    }
}

Error codes

The following ErrorCode values are supported:

  • 101 - invalid token;
  • 102 - authentication failure;
  • 103 - invalid data;
  • 104 - database error;
  • 999 - method not found.

Web API reference