This example creates a virtual export with paging – a resource that exists only at runtime, not added to your integrator.io account – in JavaScript APIs and runs it to demonstrate the record returned from the source application.
-
From the Resources menu, select Scripts.
-
At the right, click + Create script.
-
Name your new script (ex. exportVirtualPaging_Script).
-
Write the JavaScript code in the Edit content field.
-
The script must have at least one entry-point function –
handleRequest(options)below. -
It must handle any errors.
-
In this case, it calls exports.runVirtualWithPaging( options ).
-
Update
pageSizevalues based on the business need, such that the response size limit is well below the 5 MB max limit per page. Note that Celigo currently supports a maximum of 1000 pages. -
Define the export with the
optionsobject definition, as shown below in theNSObjectJSON structure:Note
The export object definition in the example below is for NetSuite. For other applications, you must use the export API endpoint (
https://api.integrator.io/v1/exports/<exportId>) endpoint to get the object definition.import { exports } from 'integrator-api'; function handleRequest(options) { let success = true; let invokeExportResponse; let nsObject; let response = {}; nsObject = return_NetSuite_Export_Obj(options); try { const pagingObj = { export:nsObject } if (options.body && options.body.pagedExportState) { pagingObj.pagedExportState = options.body.pagedExportState } invokeExportResponse = exports.runVirtualWithPaging(pagingObj); response.statusCode = 200; } catch (e) { invokeExportResponse = JSON.stringify(e); console.log(JSON.stringify(e), e.code, e.message) response.statusCode = 400; } response.body = invokeExportResponse; function return_NetSuite_Export_Obj(options) { let netSuiteObject = { "_connectionId": '6363916275366d48c0f1521d', "asynchronous": true, "pageSize": 5, "netsuite": { "type": "restlet", "skipGrouping": true, "statsOnly": false, "restlet": { "recordType": "item", "searchId": "69", "restletVersion": "suiteapp2.0", "markExportedBatchSize": 100 }, "distributed": {} }, "adaptorType": "NetSuiteExport" }; return netSuiteObject; } return { statusCode: response.statusCode, headers: {}, body: response.body, }; }
-
-
Save the script.
-
Navigate to → → .
-
Click + Create API at the upper right.
-
Enter a name (ex. Demo – exports.runVirtualPaging(options)).
-
Select the script saved in step A, exportVirtualPaging_Script.
-
Click
to open the Script editor and copy the function name (handleRequest). Paste the name into the Function field.
-
Click Save & close.
-
Navigate to → .
-
Click + Create API token at the upper right.
-
Enter a name (ex. Run virtual export paging).
-
In the Token permissions section, select Custom scopes.
-
From the JavaScript API(s) list, select the JavaScript API you created in step B, (ex. Demo – exports.runVirtualPaging(options)).
-
Click Save & close.
Open Postman and connect to the JavaScript API created above at the provided invoke URL.
-
To fetch the first page of data, the request body should be empty.
-
Copy the
pagedExportStatefrom the response, and use it as the request body to fetch the 2nd page of data. -
Similarly, fetch the remaining pages of data, by calling the API multiple times with updated
pagedExportStateas the request body.
POST /v1/apis/668c••••••••••••162/request HTTP/1.1
Host: api.integrator.io
content-type: application/json
Authorization: Bearer d56••••••••••••••••••c06
Content-Type: text/plain
{
"records":[
{"amount":1000}
]
}
{
"data": [
{
"id": "313097",
"recordType": "invoice",
"Order Type": "",
"*": " ",
"Date": "8/14/2019",
"As-Of Date": "8/14/2019",
"Period": "Aug 2019",
"Tax Period": "",
"Type": "Invoice",
"Document Number": "INV73910366",
"Name": "Ariba Customer",
"Account": "4000 Sales",
"Memo": "",
"Billing Account": "",
"Amount": "2000.00",
"CeligoAT_BigCommerceOrderID": "552",
"Item": "Demo core product 2"
}
],
"dataURIs": [
"https://tstdrv1934805.app.netsuite.com/app/accounting/transactions/custinvc.nl?id=313097&compid=TSTDRV1934805"
]
}
You can expose this JavaScript API using Celigo's API Management so your API consumers can invoke it. You'll have full control over how the API is authenticated, documented, and managed. Learn to expose a JavaScript API.