This article assumes that you have created a public integrator.io API and given it permission within an API token. See Set up My API to run an export for an example. In this example, we're running an existing NetSuite import in the My API, passing it a sample record from the calling application.
A. Edit the script
In this step, you may first add a new script(ex. MyAPI – importExample) below. Or, you can choose to modify another sample script.)
- Go to Resources > My APIs.
- Open a custom endpoint ( ex. Demo – import).
- Click to open the Script editor and edit MyAPI – importExample.
- Paste the following script to call imports.run() with the specified ID and named data object:
import { request, exports, imports, flows } from 'integrator-api' function _mainImportNS (options) { let method = options.method; let body = options.body; let queryString = options.queryString; // Get the input data that are passed in the records attribute in the request let recordsToBeImported = body.records; //Execute the import let importResponse try { importResponse = imports.run({ _id:'5ef••••••••••••••••••a36', data:recordsToBeImported }); }catch(e) { importResponse = JSON.stringify(e) } // Build response information let response = {}; // Set the response status code response.statusCode = 200; response.body = { method: method, body: body, queryString: queryString, importResponse: importResponse } return response; }
- Save and close the Script editor. If you haven’t done so already, paste the entry-point function name –
_mainImportNS
above – into the Function field. - Save and close the My API.
B. Provide the records in the calling application
The My API expects to receive records in the following format, with as many records in the array as are provided:
{
"records": [ { "id": "3097047072826", "first_name": "Demo", "last_name": "MyAPI", "email": "Demo1@celigo.com" } ]
}
The field names must correspond to the import mapping from the source application, for example:
C. Run the My API and verify the imported records
This example also uses Postman to invoke the My API (see Example 1b for a demonstration), sending a since record in the body of the request.
Then, it is good practice to open the destination app (NetSuite shown below) to confirm that the records are synced after the My API call.
See full example
Comments
Please sign in to leave a comment.