May 17, 2023 03:37 PM
Hi there,
As the title says, I'm trying to send a POST request using Fetch to a Zapier webhook. This works fine, except when the Fetch is placed inside a function, it is never sent.
Checking the network log, the request seems to be stalled indefinitely.
I tried sending the request using the same code outside of Airtable, and it's working. The request is sent to Zapier.
I've scoured Google looking for similar issues but couldn't find anything relevant. I tried async and not, try/catch, and adding headers, but nothing so far.
May 17, 2023 04:12 PM
why place it in that function?
May 17, 2023 04:30 PM
I must add a few more checks before sending the request, and the function helps reuse the code.
For now, I opted to paste the request wherever it is needed instead of calling the function, which works, but I understand it is not a good habit.
Have you encountered this issue before? do you know of any limitations of the scripting extension?
May 17, 2023 04:38 PM
it's hard for me to say without running the code in your environment myself. perhaps you need to add an 'await' before the function? also, you don't need to call the function twice. your logic can be simplified:
let table = base.getTable("Testable");
let record = await input.recordAsync('Select a record to use', table);
let bugID = record.getCellValueAsString("Bug ID");
let kustomerLink = record.getCellValueAsString("Convo Link");
if (!kustomerLink) { kustomerLink = await input.textAsync('Please paste a link to the ticket'); }
await sendReport(bugID, session.currentUser.name, kustomerLink);
May 18, 2023 11:28 AM
Hey @Avi!
Give this a shot:
let table = base.getTable("Testable");
let record = await input.recordAsync('Select a record to use', table);
let bugID = record.getCellValueAsString("Bug ID");
let kustomerLink = record.getCellValueAsString("Convo Link");
if (kustomerLink) {
await sendReport(bugID, session.currentUser.name, kustomerLink);
} else {
kustomerLink = await input.textAsync('Please paste a link to the ticket')
.then(async response => {
await sendReport(bugID, session.currentUser.name, kustomerLink);
})
}
async function sendReport (jiraID, agentName, customerLink) {
console.log("Sending...", jiraID, agentName, customerLink);
try {
await fetch('https://hooks.zapier.com/hooks/catch/3235r56vb34', {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
bug: jiraID,
agent: agentName,
kustomer: customerLink
})
})
.then(response => console.log(response.text()));
} catch (error) {
console.log(error.message);
}
console.log("Sent");
};