Calling external APIs Last updated: 13. Mar 2023

Examples and info on Docly functions to call external WEB APIs (JSON) with POST and GET. IMPORTANT: These functions are only available from the #/API folder.

HttpGet(url, [headers])

/* Basic authentication */
var headers = {
    "Authorization" : "BASIC " + docly.base64(login + ":" + password)
};

/* Call server */
var result = docly.httpGet("https://docly.net/API/Folder/Dir?id=1", data, headers);

/* Output result */
return JSON.stringify(result);

HttpPost(url, data, [headers])

Posts data serialized as JSON to url. (.NET PostAsJsonAsync)

/* Build query string */
var data = {
    id : 1
};

/* Basic authentication */
var headers = {
    "Authorization" : "BASIC " + docly.base64(login + ":" + password)
};

/* Call server */
var result = docly.httpPost("https://docly.net/API/Folder/Dir", data, headers);

/* ... */

HttpFormPost

Same as HttpPost only posting as a form. Old school but used many places.

Handle exceptions

If an exception occours you can check the "Error"

/* Call server */
var result = docly.httpPost("https://docly.net/API/Folder/Dir", data, headers);

/* Check for error */
if(result.DoclyError) docly.assert(result.DoclyError);


/* ... */