0

I am trying to send an SMS message using Twilio API in Windows 10. I enter the following request in CMD:

curl "https://api.twilio.com/2010-04-01/Accounts/ACAccount SID/Messages.json" -X POST \
--data-urlencode "To=+Phone number" \
--data-urlencode "From=+Phone number" \
--data-urlencode "Body=Ahoy" \
-u Account SID:Auth Token

And I encounter:

{"code": 20003, "detail": "Your AccountSid or AuthToken was incorrect.", "message": "Authentication Error - No credentials provided", "more_info": "https://www.twilio.com/docs/errors/20003", "status": 401}curl: (6) Could not resolve host: \

I looked up the error message from the url provided but I couldn't get much information. I verified the Auth token and SID are correct. I am using Twilio free trial account if that makes a difference. I have given up troubleshooting. Any advice would be greatly appreciated.

yvesonline
  • 3,583
  • 2
  • 15
  • 26
  • 1
    The error message says `curl: (6) Could not resolve host: \ ` indicating that the backslash was interpreted as the URL. You said you're on Windows 10 in the command prompt? The backslash `\ ` is used in Bash in Linux to split long commands over multiple lines. If you're on Windows you would need to replace `\ ` with `^`, see this [SO question](https://stackoverflow.com/questions/69068/split-long-commands-in-multiple-lines-through-windows-batch-file). – yvesonline Mar 21 '21 at 15:15
  • 1
    @yvesonline That did it! Thank you so much! – Juan Pereyra Mar 21 '21 at 16:32
  • 1
    Good stuff, I'll add it as an answer then you can [accept and vote](https://stackoverflow.com/help/someone-answers) on it. – yvesonline Mar 21 '21 at 16:49

2 Answers2

1

The error message says curl: (6) Could not resolve host: \ indicating that the backslash was interpreted as the URL.

You said you're on Windows 10 in the command prompt, the backslash \ is used in Bash in Linux to split long commands over multiple lines. If you're on Windows you would need to replace \ with ^, see this SO question.

So this should work under Windows 10 in the command prompt:

curl "https://api.twilio.com/2010-04-01/Accounts/ACAccount SID/Messages.json" -X POST ^
  --data-urlencode "To=+Phone number" ^
  --data-urlencode "From=+Phone number" ^
  --data-urlencode "Body=Ahoy" ^
  -u Account SID:Auth Token
yvesonline
  • 3,583
  • 2
  • 15
  • 26
0

Try using API Explorer, Messages -> Create a Message. See if that works and if it does, click the Show your Auth Token button and compare the cURL structure it uses vs. what you are using.

Also, although your example code looks clean, another common way this issue occurs is when smart quotes sneak in, like when you copy a code sample from Slack that isn't in a code block format.

Alan
  • 7,708
  • 2
  • 6
  • 8
  • I followed your steps and it produced the same POST request. I made sure the values for the Auth Token and Account SID matches my post above. I am able to send the request in twilio, but not in CMD. I made sure to add "C:\Windows\System32\curl.exe" to the Path variable in environment variables, In my workstation. – Juan Pereyra Mar 21 '21 at 15:39