Send a webhook from Airtable containing an array of objects
What is the problem & what have you tried?
My webhook as structured isn’t generating usable data in my scenario. Attached screenshot shows the script that structures and sends the webhook, how it looks in my scenario, and the data object as it appears in the history logs. How can I get the data I am adding in the script to appear in my scenario? I’ve tried imposing a data structure in the webhook by pasting in a string of the resulting json, which it reads in fine, but this doesn’t seem to affect the data available in the scenario.
can you copy paste the code here for testing? Use the preformatting option so it maintains it as is:
On a side note, you’ve mapped the wrong thing in the iterator. You mapped the entire JSON bundle coming from the webhook, while the iterator expects an array item.
Thanks very much for looking at this with me. I show the whole bundle in the mapping because that is the only item available to choose from. Here’s my code text:
for (let req of reqQuery.records) {
let department = req.getCellValue('Department (From Requisition)').name
let expenseCat = req.getCellValue('Expense Category').name
let itemPrice = req.getCellValue('Unit Price Adj - PU') + (req.getCellValue('Order Cost Per Line (from Purchase Order)') / req.getCellValue('Quantity Ordered'))
let payload = {
'memo': req.getCellValue('PO text') + '/' + req.getCellValue('Line Item') + ' - ' + expenseCat,
'lines': []
}
if (department == 'All') {
for (let dep of Object.keys(departmentDict)) {
payload['lines'].push({
'class': departmentDict[dep][0],
'sku': departmentDict[dep][1],
'description': req.getCellValue('Description'),
'rate': itemPrice,
'quantity': req.getCellValue('Quantity Ordered') * expenseDict[expenseCat][dep]
})
}
}
else {
payload['lines'].push({
'class': departmentDict[department][0],
'sku': departmentDict[department][1],
'description': req.getCellValue('Description'),
'rate': itemPrice,
'quantity': req.getCellValue('Quantity Ordered')
})
}
let options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload),
//'muteHttpExceptions': true
}
console.log(payload)
console.log(options['payload'])
try {
let response = await fetch(webhookUrl, options)
let result = await response.status
if (result == 200) {
plUpdateList.push({id: req.id, fields: {'purchase requisition sent to quickbooks': true}})
}
else {
console.log('Error response: ',result)
}
}
catch (error) {
console.log('Error with request')
}
}
Thanks Taylor for the help. I implemented the change you provided, ran ‘Redetermine data structure’ on the webhook module, and sent the call from the script. It still did not provide the elements of the object in a selectable way. I did notice some changes:
I am not sure why Taylor’s post was flagged and is no longer visible, it was helpful. They had suggested I not stringify the json before sending it in the API call. Also the paramater should be labled ‘body’ instead of ‘payload’.
My last response before this was my results from following that advice. Still not quite working, but it seems to be getting close.