Host Engineering Forum
General Category => General Discussion => Topic started by: trsimmons7 on November 13, 2023, 11:50:17 PM
-
I'd like to see if I can send sms using my Twilio service - they've got reams of documentation, I just don't know where to start.
From the docs for CURL --
EXCLAMATION_MARK='!'
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "Body=This will be the body of the new message$EXCLAMATION_MARK" \
--data-urlencode "From=+15017122661" \
--data-urlencode "To=+15558675310" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
How do I format for the HTTPCMD instruction?
thanks
travis
-
I'd like to see if I can send sms using my Twilio service - they've got reams of documentation, I just don't know where to start.
From the docs for CURL --
EXCLAMATION_MARK='!'
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "Body=This will be the body of the new message$EXCLAMATION_MARK" \
--data-urlencode "From=+15017122661" \
--data-urlencode "To=+15558675310" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
How do I format for the HTTPCMD instruction?
thanks
travis
Its like crickets in here.....
-
trsimmons7, the only folks that would know for sure what this should look like will be the folks at Twilio. However, based on what I looked up (and I'm completely ignorant of their API protocol requirement), it looks like it should be similar to the pic. Although, I'll tell you what I do not know.
- I assume in the Request, this would just include what I show.
- I do not know if the leading "/" is needed in front of the "api" part.
- You would have to replace the <YOUR_ACCOUNT_SID> with your relevant data as you show in your CURL coding.
- Notice in the Additional User Request Header, I included authentication stuff. However, since your CURL coding doesn't show that you may not need it and that's why I have not checked it.
- If the authorization is needed, then you'll have to replace the <Base64Encoded(AccountSID:AuthToken)> with what your is.
- The $N part is translated by our OS as meaning carriage return line feed. This is also something I do not know if you need.
- The portion "Content-Type: application/json" I'm not sure if that is needed either, nor if it goes in the Additional User Request Header portion, or the Request Body. This is something Twilio will also have to tell you.
- In the Request Body, it is a bit different than your CURL coding because your coding is not truly in JSON format. So, I put it in JSON format. It looks very confusing simply because the $" is needed to get a double-quote within a string, so that our OS doesn't think the presence of a double-quote is the end of the string, since the static string is supposed to be contained within double quotes. I hope that makes sense.
I do not have a Twilio account, so I cannot try this here at Host Engineering. You can experiment with this to see what works. Or you can get in touch with Twilio and see if they can help you with what parts go where in our HTTPCMD instruction.
I asked Bard (Google's AI), and he responded with:
POST https://api.twilio.com/2010-04-01/Accounts/<YOUR_ACCOUNT_SID>/Messages.json
Authorization: Basic <Base64Encoded(AccountSID:AuthToken)>
Content-Type: application/json
{
"To": "+15555555555",
"From": "+14155555555",
"Body": "Hello from Twilio!"
}
Remember to replace <YOUR_ACCOUNT_SID> and <Base64Encoded(AccountSID:AuthToken)> with your actual account details. You can find these details in your Twilio account dashboard.
-
I have tried to do a an HTTPCMD to Twilio in the past, and had no luck. I can get it to work through Postman, but not DmD, so not sure where I go wrong. Typically, I would have the "api.twilio.com" in the Server Name, and then "/2010-04-01/Accounts/<YOUR_ACCOUNT_SID>/Messages.json" in the Request. Last time I used HTTPCMD, I couldn't get the "Content-Type: application/json" to work in the Additional Header (but now that I see this, I was doing $0D$0A, not $N between the Auth-Token and Content-Type). I had to put it in the checkbox at the bottom.
Perhaps MarkTTU will chime in here, I think he has done something similar to this.
-
(but now that I see this, I was doing $0D$0A, not $N between the Auth-Token and Content-Type).
FYI, entering "$N" for a string literal in the editor just expands to "$0D$0A" once you enter the instruction into your rung.
-
FYI, entering "$N" for a string literal in the editor just expands to "$0D$0A" once you enter the instruction into your rung.
Ha, and here all these years I've been typing 6 characters instead of 2... All courtesy of the typewriter.
-
Thanks for the posts guys - I haven't had a chance to circle back to this one yet.
thx
travis
-
Sorry to be late to the party on this one. I've never managed to get Twilio to work directly with a DmD PLC. In the past I had an intermediate server that the DmD PLC would post to via an API we wrote and then that intermediate server connected to Twillo.
More recently I setup doing SMS directly from a DmD PLC using Telnyx. Got that up and running in an afternoon. Overall I actually prefer Telnyx service now that I've discovered it and used it a bit. Might be a touch cheaper as well. If you're going to be doing any volume of SMS you'll want to get a toll-free number to send from; they're the same price, but the carriers allow for much higher message sending rates from toll free numbers.