Deel Example
The code below is an example of a process connecting to Deel. Deel doesn't authenticate through MODLR's OAuth 2.0 flow for this use case, so this is an Advanced Integration - it authenticates using an API token and its associated client ID, both issued directly from Deel.
INFO
This process requires a Deel API token and client ID, stored as Secrets rather than hardcoded in the process.
Process Code
js
function pre() {
// This function is called once before the process is executed.
// Use this to setup prompts.
script.log('process pre-execution parameters parsed.');
}
// Endpoints:
// https://developer.deel.com/reference/getcontracts
function begin() {
script.log('process execution started.');
const token = security.getSecret("DEEL_API_TOKEN");
const clientId = security.getSecret("DEEL_CLIENT_ID");
const response = web.get("https://api.letsdeel.com/rest/v2/contracts", {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${token}`,
"x-client-id": clientId
});
if (response.status >= 200 && response.status < 300) {
console.log("Request succeeded.");
const body = JSON.parse(response.body);
console.log(body);
} else if (response.error) {
// An error occurred while sending the request (e.g., network error, timeout, etc.).
console.log("Error occurred while sending the request: " + response.error);
} else {
// The request failed with a non-success status code.
console.log("Request failed with status code: " + response.status);
console.log(response.body);
}
}
function data(record) {
// This function is called once for each line of data on the second cycle
// Use this to build dimensions and push data into cubes
}
function end() {
// This function is called once at the end of the process
script.log('process execution finished.');
}