JavaScript Library
  • 16 Apr 2024
  • 1 Minute to read
  • Dark
    Light

JavaScript Library

  • Dark
    Light

Article summary

General

The JavaScript library consists of a file named MailAndDeploy.Api.Client.js located in the SDK\Library folder of the root installation directory. It provides high-level functionality to access the API.

Initialization

Before any API call can be performed, the following syntax can be used to initialize the API connector:

Connector Initialization

MailAndDeployApiClient.InitializeConnector(EndpointUrl, AccessKey)

You have to pass the endpoint URL (that is the URL of the API Service) and the access key for the User to authenticate.

Making API Calls

Once the initialization has been completed, you can call any API Method by using the following syntax:

API Method Call

MailAndDeployApiClient.<methodname>(<parameter1>, ... <parameter2>)

The return value of such a call will be a Promise.

API Method Call

MailAndDeployApiClient.<methodname>(<parameter1>, ... <parameter2>).then(function(Response) {...});

Examples

The following example returns a DatasourceStructure that represents the Datasource with ID 947667f3-665b-4246-8073-95de881225b1:

GetDatasource Example

var Datasource = null;
MailAndDeployApiClient.GetDatasource('947667f3-665b-4246-8073-95de881225b1').then(function(Response) {Datasource = Response});

The following code changes the name of the queried datasource to MyDatasource and then persists it:

Persist Example

Datasource.Name = 'MyDatasource';
await MailAndDeployApiClient.Persist(Datasource);

Global Error Handling

When reacting to the rejection of a Promise, error handling can be done for every call individually. In some cases, however, it's better to have a single global error handling function which is called regardless of which API call leads to the error. This can be implemented using the following syntax:

Global Error Handler

MailAndDeployApiClient.OnError = function(ErrorMsg) {...}


Was this article helpful?