This article demonstrates creating a public integrator.io API to run an existing export.
-
From the Resources menu, select Scripts.
-
At the right, click + Create script.
-
Name your new script (ex. JavaScript API – export Example).
-
Write the JavaScript code in the Edit content field.
-
The script must have at least one entry-point function – _mainExport() below.
-
It must handle any errors.
-
In this case, it calls exports.run(), passing it the export’s ID, as shown below:
-
import { exports } from 'integrator-api' function _mainExport (options) { let response = {}; let invokeExportResponse; let exportResponse; // Execute the export try { invokeExportResponse = exports.run({_id:'5ef••••••••••••••••••b01'}); response.statusCode = 200; }catch(e) { invokeExportResponse = JSON.stringify(e); response.statusCode = 400; } // Create body response response.body = { exportResponse: invokeExportResponse } 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 – export).
-
Select the script saved in step A (JavaScript API – export).
-
Click
to open the Script editor and copy the function name ( _mainExport ). Paste the name into the Function field.
-
Click Save & close.
-
Navigate to
→ . -
Click + Create API token at the upper right.
-
Enter a name (ex. Postman JavaScript API).
-
In the Token permissions section, select Custom scopes.
-
From the JavaScript APIs list, select the JavaScript API you created in step B, Demo – export.
-
Click Save & close.