Articles in this section

Configure JavaScript API to run an import with supplied mapped fields

This article assumes that you have created a public integrator.io API and given it permission within an API token . See Set up JavaScript API to run an export for an example. In this example, we're running an existing NetSuite import in the JavaScript 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. JavaScript API – importExample) below. Or, you can choose to modify another sample script.)

  1. Go to ResourcesAPIsJavaScript.

  2. Open a custom endpoint ( ex. Demo – import).

  3. Click pencil.svg to open the Script editor and edit JavaScript API – importExample

  4. 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;
    }
  5. 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.

  6. Save and close the JavaScript API.

B. Provide the records in the calling application

The JavaScript 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": "JavaScript API",
      "email": "Demo1@celigo.com"
     }
  ]
}

The field names must correspond to the import mapping from the source application, for example:

360064469551-my-apis-11.png

C. Run the JavaScript API and verify the imported records

This example also uses Postman to invoke the JavaScript 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 JavaScript API call.

See full example