Send SMS via curl request

  • 1
  • Problem
  • Updated 2 years ago
I'm trying to test out different API functionality before beginning to build an application to link a client's CRM to the Ring Central API.

I've gone through the "Getting Started" tutorial, and have successfully retrieved an access token and logged in.  

I'm going through the "Message" tutorial, and I'm trying to send a POST request to send a test message. I couldn't figure out how to format the JSON correctly in the Rest Client chrome extension, so I'm replicating the POST message in the "Message" tutorial in a curl request.  Here's the request I'm running from the command line (the fields in all caps are filled in with the correct values):

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer  MY-ACCESS-TOKEN" -H "Accept: application/json"  -d '{"to": [{"phoneNumber": "PERSONAL-PHONE-NUMBER"}], "from": {"phoneNumber": "SANDBOX-ACCOUNT-NUMBER"}, "text": "this is the message"}' https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms
And here's the response I'm getting:

{
  "errorCode" : "FeatureNotAvailable",
  "message" : "The requested feature is not available",
  "errors" : [ {
    "errorCode" : "MSG-242",
    "message" : "The requested feature is not available"
  } ]
}


Any Idea what might be going wrong?

Photo of Grant Botma

Grant Botma

  • 332 Points 250 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,622 Points 5k badge 2x thumb
Has the User / Extension in the Sandbox account been enabled? (do you see a green marker next to their name while viewing in service.devtest.ringcentral.com ?)

If you are sure that User/Extension has been enabled, is the account authorized to send SMS? A good test for this is to try sending an SMS from the Desktop soft phone in Sandbox mode.
Photo of Grant Botma

Grant Botma

  • 332 Points 250 badge 2x thumb
Yes, the user extension has been enabled.  If I'm logged into my actual account, I'm able to send external text messages from the soft phone, however when I'm logged into my sandbox account and I try to send an external text, I get this error message:

"Alert: Your extension does not support external text messaging. Please contact your account administrator."

Is there any way to enable some sort of stubbed external texting in Sandbox? If not, how should I go about testing my application's texting feature?
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,622 Points 5k badge 2x thumb
In the OAuth Settings panel of the Settings for your application (where you obtained the API Keys), have you enabled the SMS permission for this app?

Here is a screenshot of what you would want to see...

Photo of Grant Botma

Grant Botma

  • 332 Points 250 badge 2x thumb
Yes, that's how I set it up.
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,622 Points 5k badge 2x thumb
Alright, so that's one question down...

I just tried this from my console successfully, using this cURL request (after obtaining a valid access_token):
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer REPLACE_WITH_ACCESS_TOKEN" -d "{\"from\":{\"extensionNumber\":\"\",\"location\":\"\",\"name\":\"\",\"phoneNumber\":\"16506429233\"},\"to\":[{\"extensionNumber\":\"\",\"location\":\"\",\"name\":\"\",\"phoneNumber\":\"14158905908\"}],\"text\":\"This is my API Explorer SMS message.\"}" "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms";
I'm using: 
curl 7.37.1 (x86_64-apple-darwin14.0) libcurl/7.37.1 SecureTransport zlib/1.2.5

I kept receiving Unsupported Media Type errors when I was using the -H flag for headers instead of --headers.

You can use our API Explorer for sending test SMS messages via the API as well. Could you try it in the API Explorer and share the response please sir.

https://developers.ringcentral.com/api-explorer/latest/index.html#/!/Messages/sendSMS
Photo of Grant Botma

Grant Botma

  • 332 Points 250 badge 2x thumb
I'm getting various versions of the same error in different environments:

via curl-

My API call:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer VALID_AUTH_TOKEN" -d "{\"from\":{\"extensionNumber\":\"\",\"location\":\"\",\"name\":\"\",\"phoneNumber\":\"SANDBOX_PHONE_NUMBER\"},\"to\":[{\"extensionNumber\":\"\",\"location\":\"\",\"name\":\"\",\"phoneNumber\":\"EXTERNAL_PHONE_NUMBER\"}],\"text\":\"This is my API Explorer SMS message.\"}" "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms";

And here's the response I'm getting:

{
  "errorCode" : "FeatureNotAvailable",
  "message" : "The requested feature is not available",
  "errors" : [ {
    "errorCode" : "MSG-242",
    "message" : "The requested feature is not available"

  }

I get the same response whether I'm using -H or --header for my header flag.

via API explorer-


and here's the response:


soft phone's response-



Here's the permissions page



Note- If I'm logged into soft phone with the non-sandbox account, I can send external text messages without any issue. Do I need to toggle anything from within my https://service.devtest.ringcentral.com account or the https://service.ringcentral.com account?

My apologies if this is overkill, I just figure that more info might be helpful!


Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,622 Points 5k badge 2x thumb
OK, I think I got it all figured out for you...

You are trying to use the main company number for the Sandbox account (you cannot send SMS from that number). What you want to do is create a new user on https://service.devtest.ringcentral.com and then...

Go to the Phones & Numbers section (URI below), add a direct number and add a phone for the user from the previous step. Also, please make sure that you have activated the user account, you can see this in the user so you can see they are enabled on the list of users.

Here is a screenshot of an account that I am able to use while sending SMS.


Please complete these steps and try again and you should be able to send the SMS from the soft phone (when you're logged in as that user in the soft phone or via the API as the newly created user and using their number as the "from" number in your API request).

Let me know.
Photo of Grant Botma

Grant Botma

  • 332 Points 250 badge 2x thumb
Fixed. Thank you so much!
Photo of Benjamin Dean

Benjamin Dean, Alum

  • 8,622 Points 5k badge 2x thumb
Glad to hear you're back in action.