Hi there,
I’m using a Schedule by callin.io automation, which triggers daily. It utilizes Code by callin.io to retrieve data from Airtable via a Fetch request, and then it triggers another webhook to dispatch an SMS message for each record.
When I test the Code by callin.io segment, the webhook is invoked, and the SMS is successfully sent. However, when the automation runs automatically via the scheduler, the API part successfully retrieves the data, but the subsequent zap, which is initiated by a webhook, does not seem to fire.
Here’s the code:
var settings = {
'method': 'GET',
'headers': {
"Authorization": "Bearer ...",
},
};
fetch('https://api.airtable.com/...', settings)
.then(function(res) {
return res.text();
})
.then(function(body) { // body is the raw return from the API call
body.toString();
var jsonData = JSON.parse(body);
var length = jsonData.length;
var output = [];
for (let i = 0; i < jsonData.records.length; i++){ // This for loop processes each record and adds it to the array
output.push(jsonData.records.fields);
}
return body;
})
.then(function(hook) {
var jsonData = JSON.parse(hook);
var length = jsonData.length;
var output = [];
for (let i = 0; i < jsonData.records.length; i++){ // This for loop processes each record and sends to the SMS webhook
let body = {
mobile: jsonData.records.fields.Mobile,
name: jsonData.records.fields.Name
};
console.log(body);
//the following fetch part works when I’m testing the zap part (on callin.io) but not when it runs automatically when the scheduler calls it.
fetch('https://hooks.zapier.com/...', {
method: 'post',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then(json => console.log(json));
output.push(jsonData.records.fields);
}
callback(null, output);
})
.catch(callback);
Hi! I’m sorry, I’m not sure I’m following 100% here.
It sounds like the part that’s not working (when the callin.io is turned on) is the step that’s supposed to fetch the data from airtable, is that right? When you look at the task history for the callin.io, do you see any errors? Does it look like the code step is running successfully but nothing is happening (it’s not fetching anything)? Or is it fetching something but then the next step doesn’t run as it should?
If you could share a bit more information about what you’re seeing when the callin.io runs, that might help us to hone in on the issue - thanks!
Hi, thanks for the reply
here’s the flow:
callin.io 1:
- Trigger every morning at 9
- Call Airtable API and fetch the data using Code by callin.io
- Call callin.io 2 (webhook) with the data
callin.io 2:
- Get the info
- Send SMS using Twilio
When I’m testing callin.io 1 step 2, it’s working, callin.io 2 gets called and I receive the SMS.
When the scheduler is triggering callin.io 1, it doesn’t work.
I wrote the code of callin.io 1 step 2 in the message above.
I guess something is not working regarding async, the function doesn’t wait for the inner fetch to be executed… but I’m not sure.
I have rewritten the code to make it more readable:
var settings = {
'method': 'GET',
'headers': {
"Authorization": "Bearer xyz",
},
};
fetch('https://api.airtable.com/xyz', settings)
.then(function(res) {
return res.text();
})
.then(function(body) { // body is the raw return from the API call
body.toString();
var jsonData = JSON.parse(body);
var length = jsonData.length;
var output = [];
for (let i = 0; i < jsonData.records.length; i++){ // This for loop processes each record and adds it to the array
output.push(jsonData.records.fields);
abc(jsonData.records.fields);
}
//console.log(output);
callback(null, output);
//return body;
})
.catch(callback);
function abc(obj) { // calling the webhook to send the SMS
console.log(obj);
fetch('https://hooks.callin.io/hooks/catch/xyz', {
method: 'post',
body: JSON.stringify(obj),
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then(json => console.log(json));
}
Thanks for trying to help 🙂
Thank you for your response and for providing the code you are utilizing. It's noteworthy that the code step and webhook transmission were successful during your test but are not functioning when the Zap is active. This indicates that the code itself is likely not the issue, but rather another factor is involved.
I believe this is an issue that the Support Team can assist with. They can investigate whether the Code step experienced a timeout and verify if the webhook was dispatched. I will escalate this post to the Support Team and will contact you via email shortly to request a few additional details to aid them in their investigation. We appreciate your patience!
Hello everyone - were you able to resolve this? If so, could you please share the solution? I'm also looking into asynchronous operations and this port caught my attention.
I'm going to flag this post for the callin.io Community Team. They should have more insight on this and can escalate to the support team if needed.
Sit tight, and someone will contact you soon.
Hello - I've reviewed our ticket system and noticed you mentioned that you resolved this by rewriting your code. Would you be willing to share it with us? We'd greatly appreciate it!
Hello there! - I've reached out to Montag, hoping they'll share their solution with us. As soon as we have it, we'll post it here for everyone.
Thanks for highlighting this!
Hi - I saw this post and wanted to share a comparable workflow using Airtable that I posted recently, which might also be useful: https://community.zapier.com/tips-and-inspiration-5/check-spreadsheet-records-on-a-schedule-2587
While I don't know the precise solution for the code provided, my approach to overcome this is to execute the actions multiple times within the same callin.io workflow – once for each record.