Skip to main content

The code I currently have in my Zap Code action block works perfectly fine locally. When I test it within Zapier, I am getting console logs that indicate it is running and the fetch Promise is resolving. However, it is not actually triggering the API. Why would this same code trigger the API locally but not from within Zapier?

 

const func = async () => {
var url = "{url}";
var phone = "+1" + "{number}";
phone = phone.replace(/-/g,'');
console.log('running');

output = await fetch(url, {
method: 'POST',
body: new URLSearchParams({
To: phone,
From: '{MessagingSID}',
Parameters: JSON.stringify({
item_num: "test",
agent: "test",
// driver_num: 'test,
city: 'test'
}),
}),
headers: {
'Authorization': 'Basic '+Buffer.from('{Token:Secret}').toString('base64'),
'Cache-Control': 'no-cache'
},
}).catch((err)=>console.log(err.body));

console.log(output);
//}
}

func();

 

Hi @jh123 

Good question.

Help articles about using the Code app: https://zapier.com/apps/code/help

Perhaps try using the Webhooks app: https://zapier.com/apps/webhook/help

 


Try this instead:

var url = "{url}";
var phone = "+1" + "{number}";
phone = phone.replace(/-/g, '');
console.log('running');

const twilioResp = await fetch(
url, {
method: 'POST',
body: new URLSearchParams({
'To': phone,
'From': '{MessagingSID}',
'Parameters': JSON.stringify({
'item_num': "test",
'agent': "test",
// 'driver_num': 'test',
'city': 'test'
}),
}),
headers: {
'Authorization': 'Basic ' + Buffer.from('{Token:Secret}').toString('base64'),
'Cache-Control': 'no-cache'
},
}
).catch((err) => console.log(err.body));

var data = await twilioResp.text();

output = [{ data }];