Hello,
I am trying to sent an SMS using “code by zapier” and javascript. My SMS provider tells me that I need to use this javascript code.
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <api_key>");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"message": "This is test and \n this is a new line",
"to": "+35799999999999",
"bypass_optout": true,
"sender_id": "SMSto",
"callback_url": "https://example.com/callback/handler"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.sms.to/sms/send", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
But when I run this on zapier I get the following error.
If you are doing async (with fetch library) you need to use a callback!
I have no experience with javascript but I think it has something to do with the last 3 lines of this code. I searched for solutions and found a few suggestions, but I don’t know how to implement them correctly and whatever I try the error keeps changing.
What is the correct way of using this code to send SMS using javascript on zapier?
Thanks