1

My goal is to send a text message in VBA with Twilio's API by using WinHttpRequest and a POST call.

I put together a custom call using the WinHttpRequest for a basic SMS message and that worked. I can send text messages just fine.

But then I tried adding the MediaURL to the data, and it ignored the URL (no image attached to SMS). I confirmed the URL was valid by testing it in the Visual Studio project and it was able to send just fine.

I went back and tried sending a test image on twilio's servers and it works. I copied the same image to a server and it won't work.

WORKS

HTTPReq.send ("Body=Hi Brent, Hello From Me!&From=+1XXXXXXXXXX&To=+1XXXXXXXXX&MediaUrl=https://demo.twilio.com/owl.png")

DOESN'T WORK

HTTPReq.send ("Body=Hi Brent, Hello From ME!&From=+1XXXXXXXXXX&To=+1XXXXXXXXXX&MediaURL=https://smarttanktester.com/wp-content/uploads/2018/10/owl.png")

(Phone numbers removed).

I tested with a few more images from their site and they work.

So it appears that URLs external to their server are being ignored. My guess is that I have something configured wrong from my end.

Here is my code.

TargetURL = "https://api.twilio.com/2010-04-01/Accounts/XXX/Messages"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")

HTTPReq.Open "POST", TargetURL, False

HTTPReq.setRequestHeader "Accept", "application/json"
temp = "Basic " & EncodeBase64
HTTPReq.setRequestHeader "Authorization", temp
HTTPReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

HTTPReq.send ("Body=Hi Brent, Hello From Me!&From=+1XXXXXXXXXX&To=+1XXXXXXXXXX&MediaURL=https://smarttanktester.com/wp-content/uploads/2018/10/owl.png")

Any help is greatly appreciated.

Dan
  • 59,490
  • 13
  • 101
  • 110
Brent
  • 11
  • 1
  • Are you passing your authentication info?account_sid and auth_token https://www.twilio.com/sms/api and https://www.twilio.com/docs/usage/your-request-to-twilio – QHarr Oct 02 '18 at 17:36
  • Yes. I can send regular SMS and MMS with images that have a URL on twilio.com. Just can't send a media image on a different server. – Brent Oct 03 '18 at 01:15
  • That is odd. It might be best to get in touch with [Twilio support](https://www.twilio.com/help/contact) and get them to look into the messages that you tried to send with an image but got ignored. I don't imagine the issue is with your code if you can get it to work with images on twilio.com. – philnash Oct 05 '18 at 07:09

0 Answers0