Using Web API

Web API reference

Introduction

This API allows applications to communicate with backend code of Aurora Cloud. You can create your custom frontend which would interact with Aurora Cloud backend via Web API. Note that the application which uses Web API doesn't have to be written in PHP, 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 Aurora Cloud 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://aurora-cloud.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 Aurora Cloud 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://aurora-cloud.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: 'StandardAuth',
    Method: 'Login',
    Result: {
        AuthToken: 'token_value'
    }
}

Subsequently, in order to receive data of that specific authenticated user, you'll need to supply their AuthToken value obtained upon successful authentication. For example, to get user's list of files, you'll need to send the following request:

javascript

$.ajax({
    url: 'index.php?/Api/',
    type: 'POST',
    async: true,
    dataType: 'json',
    data: {
        Module: 'Files',
        Method: 'GetFiles',
        AuthToken: 'token_value',
        Parameters: '{"Type":"personal","Path":"","Pattern":""}'
    },
    success: function (oResponse) {
        if (oResponse)
        {
            var
                oMainResult = oResponse.Result,
                aFiles = oMainResult.Items
            ;
            console.log('aFiles', aFiles);
        }
    }
});

C#

string url = "https://aurora-cloud.afterlogic.com/?/Api/";
using (var client = new WebClient())
{
        client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        string strData = "Module=Files&Method=GetFiles&AuthToken=token_value&Parameters={Type: \"personal\", Path: \"\", Pattern: \"\" }";
        strData = client.UploadString(url, strData);
        Console.WriteLine(strData);
}

This request will return JSON-formatted list of files:

{
    Module: 'Files',
    Method: 'GetFiles',
    Result: { 
        Items: [{Id: "image.png", Type: "personal", Path: "", FullPath: "/image.png", Name: "image.png", Size: 1813, IsFolder: false, IsLink: false, LinkType: "", LinkUrl: "", LastModified: 1475498855, ContentType: "image/png", Iframed: false, Thumb: true, ThumbnailLink: "", OembedHtml: "", Shared: false, Owner: "", Content: "", IsExternal: false }], Quota: { Used: 21921, Limit: 62914560 },
        Quota: {
            Used: 157344,
            Limit: 62914560
        }
    }
}

In case of error, response of the following kind is returned:

{
    Module: 'Files',
    Method: 'GetFiles',
    Result: false,
    ErrorCode: 102
}

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