Skip to content

Creating an integration

MODLR allows you to integrate with external tools such as Xero, SalesForce etc.

Integrations Page

In the left sidebar, click the "Integrations" button. This will redirect you to a page listing all the current available integrations. Click on the specific platform you want to integrate with.

Integrations

TIP

You will need to find the specific API documentation for the integration you're after.

Creating Integrations

Once you've picked your specific platform, you can hit the "New Connector" button top right, this will prompt for some details before we can continue setting up the integration. Once you have filled out the details, you will be redirected to the platforms website to authenticate against that platform which allows MODLR access to make requests to that platform on your behalf.

Create Integration

Integrating with a Process

Once you've got a valid integration setup, you can now start writing a process to pull in the data from that platform using the script.getOAuth method, along with the web.get function.


SalesForce Example

The code below is a rough example of what a process connecting to SalesForce could look like that makes a basic request using the tokens from script.getOAuth.

js

function pre() {
    //this function is called once before the processes is executed.
    //Use this to setup prompts.
    script.log('process pre-execution parameters parsed.');
}

// Endpoints:
// https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_discoveryresource.htm
function begin() {
    script.log('process execution started.');
    const API_VERSION = "v54.0";
    const strAuthData = script.getOAuth("CONNECTOR_NAME");
    if (strAuthData == "") {
        return;
    }

    const authData = JSON.parse(strAuthData);
    const path = `/services/data/${API_VERSION}/sobjects/`;
    const response = web.get(instanceUrl + path, {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${authData['access_token']}`
    });

    if (response.status >= 200 && response.status < 300) {
        console.log("Request succeeded.");
        console.log(response.body);
        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.');
}