- 16 Apr 2024
- 1 Minute to read
- DarkLight
JavaScript Library
- Updated on 16 Apr 2024
- 1 Minute to read
- DarkLight
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:
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:
MailAndDeployApiClient.<methodname>(<parameter1>, ... <parameter2>)
The return value of such a call will be a Promise.
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:
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:
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:
MailAndDeployApiClient.OnError = function(ErrorMsg) {...}