Help

Using the scripting extension, I'm trying to send a request to a webhook but it is never sent.

Topic Labels: Automations
1577 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Avi
4 - Data Explorer
4 - Data Explorer

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.

 
Has anybody encountered this issue before?
Appreciate any help and suggestions 🙏
 
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) {
    sendReport(bugID, session.currentUser.name, kustomerLink);
} else {
    kustomerLink = await input.textAsync('Please paste a link to the ticket')
    .then((r) => {
        sendReport(bugID, session.currentUser.name, kustomerLink);
    })
}

async function sendReport (jiraID, agentName, customerLink) {
    console.log("Sending...", jiraID, agentName, customerLink)

    try {
        const response = await fetch('https://hooks.zapier.com/hooks/catch/3235r56vb34/', {method: 'POST', "Content-type": "application/json", body: JSON.stringify({
            bug: jiraID,
            agent: agentName,
            kustomer: customerLink
        })});
        console.log(await response.text());
    } catch (e) {
        console.log('error', e);
    }
    console.log("Sent")
}
4 Replies 4
Matthew_Carrano
6 - Interface Innovator
6 - Interface Innovator

why place it in that function?

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?

Matthew_Carrano
6 - Interface Innovator
6 - Interface Innovator

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);

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");
};