Generic Resource
PEPPERI NOTIFICATION SERVICE
Actions Queue
CPI Node
TODO training
Powered By GitBook
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
1
response = {success:true, errorMessage:"", resultObject:{}}
Copied!
1
response = {success:true, errorMessage:""}
Copied!

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.

1
exports.main = async (Client) => {
2
var response = {};
3
4
// example of writing to log
5
Client.addLogEntry("Info", "Start GetTransactions");
6
7
var options = {
8
// geting the base url for pepperi api
9
uri: Client.BaseURL + '/transactions',
10
qs: {
11
'page_size': 1
12
},
13
headers: {
14
// geting pepperi brearer token of current user for pepperi api
15
'Authorization': ' Bearer ' + Client.OAuthAccessToken
16
},
17
json: true // Automatically parses the JSON string in the response
18
};
19
try{
20
// using request-promise module
21
const res = await Client.Module.rp(options);
22
Client.addLogEntry("Info", "Got result = " + JSON.stringify(res));
23
response.success = true;
24
response.resultObject = res;
25
}
26
catch(error){
27
Client.addLogEntry("Error", "Failed GetTransactions: " + error);
28
response.success = false;
29
response.errorMessage = error;
30
response.resultObject = null;
31
}
32
return (response);
33
};
Copied!
Last modified 9mo ago