Procore Example
The code below is an example of a process connecting to Procore, making a basic request using the tokens from a Standard Integration.
INFO
This process requires a Standard Integration to have been set up with Procore - 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("Procore Company ID", "companyId", "");
}
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://api.procore.com/rest/v1.0/projects?company_id=${companyId}`, {
"Authorization": `Bearer ${authData.access_token}`,
"Procore-Company-Id": companyId
});
if (response.status >= 200 && response.status < 300) {
const projects = JSON.parse(response.body);
console.log(`Projects returned: ${projects.length}`);
console.log(projects);
} 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.');
}