This example creates a virtual export – a resource that exists only at runtime, not added to your integrator.io account – in My APIs and runs it to demonstrate the record returned from the source application.
Contents
A. Write the script
- From the Resources menu, select Scripts.
- At the right, click + Create script.
- Name your new script (ex. exportVirtual_Script).
- Write the JavaScript code in the Edit content field.
- The script must have at least one entry-point function – main_exportVirtual() below.
- It must handle any errors.
- In this case, it calls exports.runVirtual(), passing it the export’s ID.
- Define the export with the options object definition, as shown below in the
NSObject
JSON structure:
/* * handleRequest function stub: * * The name of the function can be changed to anything you like. * * The function will be passed one 'options' argument that has the following fields: * 'method' - http request method (uppercase string). * 'headers' - http request headers (object). * 'queryString' - http request query string (object). * 'body' - parsed http request body (object, or undefined if unable to parse). * 'rawBody' - raw http request body (string). * * The function needs to return a response object that has the following fields: * 'statusCode' - http response status code (number). * 'headers' - http response headers overrides (object, optional). * 'body' - http response body (string or object). * Throwing an exception will signal an error. */ import { exports } from 'integrator-api' function main_exportVirtual (options) { let NSObject; let invokeExportResponse; let response = {}; NSObject = return_NS_Export_Obj (options); //Execute the export try { invokeExportResponse = exports.runVirtual({export:NSObject}); response.statusCode = 200; } catch(e) { invokeExportResponse = JSON.stringify(e); response.statusCode = 400; } // Create body response response.body = invokeExportResponse; return { statusCode: response.statusCode, headers: { }, body: response.body } } function return_NS_Export_Obj (options) { let NSObject; let amount = options.body.records[0].amount; NSObject = { "_connectionId": "5e9de3074242783b222f56e0", "netsuite": { "type": "restlet", "skipGrouping": true, "statsOnly": false, "restlet": { "recordType": "invoice", "searchId": "6763", "criteria": [ { "field": "amount", "operator": "greaterthan", "searchValue": <amount>, // Use param received from request } ] }, "distributed": { "disabled": false, "forceReload": false, "executionContext": [ "userinterface", "webstore" ], "executionType": [ "create", "edit", "xedit" ] } }, "adaptorType": "NetSuiteExport" } return NSObject; }
- Save the script.
B. Create the My API
- Navigate to Resources > My APIs.
- Click + Create My API at the upper right.
- Enter a name (ex. Demo – exports.runVirtual(options)).
- Select the script saved in step A, exportVirtual_Script.
- Click
to open the Script editor and copy the function name (main_exportVirtual). Paste the name into the Function field.
- Click Save & close.

C. Get an API token
- Navigate to Resources > API token.
- Click + Create API token at the upper right.
- Enter a name (ex. Run virtual export).
- In the Token permissions section, select Custom scopes.
- From the My APIs list, select the My API you created in step B, (ex. Demo – exports.runVirtual(options)).
- Click Save & close.
D. Test the virtual export
Open Postman and connect to the My API created above at the provided URL, with the following values:
POST /v1/apis/5f3322bbcc1912681726f7d6/request HTTP/1.1
Host: api.staging.integrator.io
content-type: application/json
Authorization: Bearer d56••••••••••••••••••c06
Content-Type: text/plain
{
"records":[
{"amount":1000}
]
}
Sample response
{ "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" ] }
Comments
0 comments
Please sign in to leave a comment.