In a rare situation, you might need to extract the information from the error retry data for further research. Assuming you are working with a custom flow, one way to automate the process is to write a postSubmit hook to send the payload info to a listener in a real-time flow.
Use the following steps to create a pre map, post map, or post submit import hook script:
-
Open a flow, click ... on the import step, and click the hook icon.
-
For Hook type, choose Script or Stack depending on where you want to store the script.
-
In the Pre map, Post map, or Post submit section, enter the function name as defined in the script. You can select another script from the Scripts list or click the Edit (
) button to code a new one.
Note
You can leave the function name blank if there is only one function in the selected script. However, if the selected script contains two or more functions, you must provide the function name to be executed; otherwise, the first function present in the script automatically populates as the function name.
-
Click the pencil
beside the selected script to open the Script editor where you can preview the data input and output and perform any modifications to the code if required.
The following sample code sends the response data to an integrator.io listener (webhook) for further processing, only when the response is not successful:
/*
* postSubmitFunction 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:
* 'preMapData' - an array of records representing the page of data before it was mapped.
* A record can be an object {} or array [] depending on the data source.
* 'postMapData' - an array of records representing the page of data after it was mapped.
* A record can be an object {} or array [] depending on the data source.
* 'responseData' - an array of responses for the page of data that was submitted to the
* import application. An individual response will have the following
* fields:
* 'statusCode' - 200 is a success. 422 is a data error. 403 means the connection went
* offline.
* 'errors' - [{code: '', message: '', source: ‘’}]
* 'ignored' - true if the record was filtered/skipped, false otherwise.
* 'id' - the id from the import application response.
* '_json' - the complete response data from the import application.
* 'dataURI' - if possible, a URI for the data in the import application (populated
* only for errored records).
* '_importId' - the _importId currently running.
* '_connectionId' - the _connectionId currently running.
* '_flowId' - the _flowId currently running.
* '_integrationId' - the _integrationId currently running.
* 'job' - the job currently running.
* 'settings' - all custom settings in scope for the import currently running.
*
* The function needs to return the responseData array provided by options.responseData.
* The length of the responseData array MUST remain unchanged. Elements within the
* responseData array can be modified to enhance error messages, modify the complete
* _json response data, etc.
* Throwing an exception will fail the entire page of records.
*/
import { exports } from 'integrator-api'
function postSubmit (options) {
// Response data contains error
if (options.responseData.statusCode != '200') {
/* Send data to a listener */
exports.run({_id: '••••••••••••••••', listenerData: options.responseData})
}
return options.responseData
}
It is important to note that the response data will not contain an error ID that you can use to manage the error automatically when attempting to retry or resolve the error.