Hello, I’m trying to use twilio to send a SMS whenever an order is ready, I was wondering if this can be done via printing job or if it has to be a script, what programming language should I use? Thank you
Not sure about print job, depends what’s available twillo end.
Script for sure should be posible, if it’s just notification and not listing orders on ticket then wouldn’t even be that hard.
Scripts are jscript, .net take on java, pretty straight forward to get used to if know coding.
FYI tutorial topic for positing tutorials, have changed to question.
There are numerous examples of remote api post/requests in my PMS intergration topic.
On Twilio you have the URL to make the API call and you need to send SID, Account ID and Auth token, I was reading the samba kb to integrate SMS sending but that doesn’t seem to work, I’m just trying to send notification when an order is ready, nothing crazy
URL is agiven, it depends how they want to receive the other data, if its part of the url the print method may work, if they want json etc as post data you may have to do a script.
Script would be faily basic for a api post for a ready notification.
I’ve been trying to make a script in JScript but I can’t get the hang of it… I have a function but is throwing a “syntaxes error” I read your post but I couldn’t figure how to pass multiple arguments I define a variable which is URL, then I need to send a post request with a from number, to number and the body of the message, so I have al four variables but I don’t know what helper to use so I have something like this:
var url = ‘url goes here’;
var from = ‘from number goes here’;
var to = ‘recipient’s number goes here’;
var body = ‘message content goes here’;
var response = web.PostJson(url,from,to,body); var response Object = JSON.parse(response);
Thanks for your help
Can you share your actual script so we can help you troubleshoot? Also, having a quick look at the API documentation you will have to authorize first before sending any SMS messages.
var formBody = new Object(); formBody.from = **"SENDER PHONE NUMBER"**; formBody.to = **"RECEIPIENT PHONE NUMBER"**; formBody.body = "Message Content"; data = JSON.stringify(formBody); var url = **'https://ACCOUNT_ID:AUTH_TOKEN@api.twilio.com/2010-04-01/Accounts/ACCOUNT_ID/Messages.json**'; var response = web.Upload(url,data); var responseObj = JSON.parse(response); return responseObj;
This is what I have in samba, Twilio API documentation:
The post json helper expects 4 parameters.
From memory url, data, username and password.
You could try sending fake user and password if http auth is not used.
If not look at webupload I think the alternative without auth is.
I tried with web.Upload but is telling me the same thing, that one of the arguments is invalid and both of them when I return typeof is coming back as a string, so I don’t know what could be wrong
The method PostJson() expects all strings as parameters. You’ve declared contact as an object which is why no method matches the signature.
The request body is not a serialised object. Using Twilio’s curl example and pointing it to my internal server to dump the body and headers, it yields this as the request:
so your content should be something like this:
var contact = ‘Body=’ + messageVarHere + ‘&From=’ + fromVarHere + ‘&To=’ + toVarHere;
I found its much easier to use clicksend and the url printer. Simple string to make it work.
Yes contact is an object but then I use JSON.stringify to convert it into string, so how can you add several key : values to a json object?
Not according to the example given on Twilio’s website.
The request body I showed you that I dumped would be the exact same format as sent to Twilio.
I don’t see any mention of serialising anything. But let me take a look at their C# SDK source and I’ll let you know.
It seems, at a glance, the only time a JSON library is called is when returning the response after sending a message. So no serialisation is happening with request body.
As Memo said your using the contact variable rather than the parse data variable…
Also just try declaring username and password vars with fake details or quote username and password so they are used as strings rather than vars. not sure if will work.
I did it using the string as you suggested and I’m just getting a blank window as response
If I do the same thing using httpbin, the it shows the data sent as form data, which should be working, but I don’t know how to troubleshoot what’s wrong, I tried in post post man when I send the to, from and body as x-www-urlencode it works just fine, so what could be wrong??
That shows similar setup with basic auth I used for 7shifts.
Do you know how to send an API key as a header using JScript?
Look at my post above it sends Api key