Generic Resource
Actions Queue
CPI Node
TODO training

ExecutedCode - Node.js documentation

All updates through API should be posted into the "DraftCode" and are automatically moved to ExecutedCode after posting a Publish request

must return a response object, for async/code_jobs the success property is mandatory, errorMessage is needed in case of failure and resultObject is optional returned body

response = {success:true, errorMessage:"", resultObject:{}}
response = {success:true, errorMessage:""}

Node.js supported functions :

  • response = {success:true/false} MANDATORY

    returns the result object at the end of the Executed Code.

  • Client.BaseURL; returns API base URL (production/sandbox/EU server)

  • Client.OAuthAccessToken; returns OAuth Access Token used for API requests.

  • Client.addLogEntry("DEBUG" ,"base url got is: " + Client.BaseURL); adds a log entry to Job Execution Log (optional values: "DUBUG"/"ERROR"/"INFO")

  • Client.Module.{modulename}; using installed module

  • Client.ExecutionUUID; execution identifier (UUID)

  • Client.CodeJobUUID; codejob identifier (UUID)

  • Client.NomberOfTry; current execution try

  • Client.AddonUUID; addon identifier (UUID), only for AddonJob type

  • Client.EncryptedAddonUUID; addon key identifier, only for AddonJob type

  • Client.CodeRevisionURL; addon file path, only for AddonJob type

  • Client.AssetsBaseUrl; addon file folder path, only for AddonJob type

  • Request.path; returns a relative URL request

  • Request.query; returns list of query parameters

  • Request.body; returns the raw payload to the code_job

  • Request.originalUrl; returns a full URL request

  • Request.method; POST/GET

Example of HTTP Request to Pepperi API within the Executed code

Please note: the code should be posted to "DraftCode" and be escaped (e.g: \") into a standard JSON string.

exports.main = async (Client) => {
var response = {};
// example of writing to log
Client.addLogEntry("Info", "Start GetTransactions");
var options = {
// geting the base url for pepperi api
uri: Client.BaseURL + '/transactions',
qs: {
'page_size': 1
headers: {
// geting pepperi brearer token of current user for pepperi api
'Authorization': ' Bearer ' + Client.OAuthAccessToken
json: true // Automatically parses the JSON string in the response
// using request-promise module
const res = await Client.Module.rp(options);
Client.addLogEntry("Info", "Got result = " + JSON.stringify(res));
response.success = true;
response.resultObject = res;
Client.addLogEntry("Error", "Failed GetTransactions: " + error);
response.success = false;
response.errorMessage = error;
response.resultObject = null;
return (response);