Skip to content

QuickBooks Example

The code below is an example of a process connecting to QuickBooks, making a request using the tokens from a Standard Integration.

INFO

This process requires a Standard Integration to have been set up with QuickBooks - see Creating an Integration. CONNECTOR_NAME below must match the name of the connection you created there.

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.');
    script.prompt("QuickBooks Realm ID", "realmId", "");
}

function begin() {
    // This function is called once at the start of the process
    script.log('process execution started.');

    const authData = JSON.parse(script.getOAuth("CONNECTOR_NAME"));

    const response = web.get(`https://quickbooks.api.intuit.com/v3/company/${realmId}/preferences?minorversion=65`, {
        "Authorization": "Bearer " + authData.access_token,
        "Content-Type": "application/json",
        "Accept": "application/json"
    });

    if (response.status >= 200 && response.status < 300) {
        const body = JSON.parse(response.body);
        console.log(body.Preferences);
    } 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.');
}