The DevXP engineering team hosts office hours every Thursday at 11 a.m.
Pacific Time where we answer your questions live and help you get up and
running with Flatfile. Join
us!
After your customers have imported their data, the process of transmitting that
data to an external destination or network is referred to as “egress out.”
This code listens for a job event of type workbook:submitAction and when
triggered, it retrieves the Sheets and records associated with the workbook.
It then prepares the data and sends a POST request to a specified webhook URL
using Axios. The payload includes information about the Sheets, records, and
other relevant data.
If the request is successful, it marks the job as complete. If there is an
error, it marks the job as failed.
Copy the value of the path after webhook.site for Your unique URL.
Next, add the following to your default export function.
//your workbook should have an action that looks like thisactions:[{operation:'submitActionFg',mode:'foreground',label:'Submit data elsewhere',type:'string',description:'Submit this data to a webhook.',primary:true,},{...}],settings:{trackChanges:true,}
red.on("job:ready",{job:"workbook:submitAction"},async(event:FlatfileEvent)=>{const{ jobId, workbookId }= event.context;const{data: workbook }=await api.workbooks.get(workbookId);const{data: workbookSheets }=await api.sheets.list({ workbookId });const sheets =[];for(const[_, element]of workbookSheets.entries()){const{data: records }=await api.records.get(element.id); sheets.push({...element,...records,});}try{await api.jobs.ack(jobId,{info:"Starting job to submit action to webhook.site",progress:10,});// TODO: place your webhook url hereconst webhookReceiver ="https://webhook.site/...";const response =awaitfetch(webhookReceiver,{method:"POST",headers:{"Content-Type":"application/json",},body:JSON.stringify({workbook:{...workbook, sheets,},}),});if(response.status===200){const responseData =await response.json();const rejections = responseData.rejections;if(rejections){const outcome =awaitresponseRejectionHandler(rejections);await api.jobs.complete(jobId, outcome);}await api.jobs.complete(jobId,{outcome:{message:`Data was successfully submitted to webhook.site. Go check it out at ${webhookReceiver}.`,},});}else{thrownewError("Failed to submit data to webhook.site");}return;}catch(error){console.error(error);await api.jobs.fail(jobId,{outcome:{message:"This job failed probably because it couldn't find the webhook.site URL.",},});return;}});// See full code example (https://github.com/FlatFilers/flatfile-docs-kitchen-sink/blob/main/javascript/shared/workbook_submit.js)