Incognito Mode
When Incognito mode is enabled on an importer, API and webhook access in unavailable, and records must be submitted to your backend using the onSubmit hook
You can send data to your backend using the onSubmit
hook.
onSubmit(records)
This hook is called when a user submits the importer. The records
array passed to it contains all rows in the spreadsheet.
The onSubmit
hook expects you to submit data to your backend in whatever way you want. You are passed a JS array of records, and expected to handle the submission to your API or backend from there.
This function must return an object with three properties:
message
: (required) A success or error message to display to the user.errors
: (required): An object that specifies which rows a backend error occurred on. Please take a look at the examples below for how to pass backend errors back to the spreadsheet UI.recordsToDisplay
: (optional): By default, when backend errors are present, the importer will only display the records with errors. The importer assumes that all records that didn’t have errors were imported successfully in your backend. There might be situations in which an error on one row prevents you from importing other rows (or, perhaps, all rows). TherecordsToDisplay
property allows you to specify which records/rows should still be shown to the user for re-import after any backend errors are fixed.
Example: Handling a Successful Backend Import
If there were no backend errors, pass back an empty errors object and a message to show to the user like so:
Example: Handling Backend Errors
Each record passed to the onSubmit
hook will have a unique identifier location under record._meta.id
. In this case of a backend validation or error occurring, you can use this identified to tell the importer to show a relevant error message for each row with an error.