MYOB AccountRight Example
The code below is an example of a process connecting to MYOB AccountRight, making a request using the tokens from a Standard Integration.
INFO
This process requires a Standard Integration to have been set up with MYOB - see Creating an Integration. CONNECTOR_NAME below must match the name of the connection you created there. It also requires your MYOB API key, stored as a Model Variable, and the AccountRight API's base URL for your region.
Process Code
js
// Model Variables - set these under Model > Variables
var primaryURL = script.variableGet("myob.url"); // e.g. "https://api.myob.com/accountright/"
var clientKey = script.variableGet("myob.clientKey"); // your MYOB API key (x-myobapi-key)
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("MYOB Company File ID", "companyFileId", "");
}
function begin() {
// This function is called once at the start of the process
script.log('process execution started.');
var authData = JSON.parse(script.getOAuth("CONNECTOR_NAME"));
var response = web.get(primaryURL + companyFileId + "/Company/Preferences", {
"Authorization": "Bearer " + authData.access_token,
"x-myobapi-key": clientKey,
"x-myobapi-version": "v2"
});
if (response.status >= 200 && response.status < 300) {
var 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.
script.abort("MYOB API Request Failed with status code: " + response.status);
}
}
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.');
}