News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
getting error 415 Unsupported Media Type when sending SMS with sandbox app
Tags: sending sms
Jan 16, 2022 at 6:31pm   •   2 replies  •  0 likes
ken-nye

Im getting error 415 Unsupported Media Type when sending SMS with sandbox app

APP ID VRbX8zVSRVeOvf0SoKM_1Q

I know my credentials are correct because I can 'GET' the messages I sent using the "try it out"
this is the body of the Json request

{
  "to": [{"phoneNumber": "+15555552586"}],
  "from": {"phoneNumber": "+15555552434"},
  "text": "The ARG is blank"
}

I am using the correct number and extension.
here is the header of the last request

{
  Server: nginx
  Date: Mon, 17 Jan 2022 02:21:20 GMT
  Connection: keep-alive
  RCRequestId: 2865d8f2-773c-11ec-84a0-005056bb9f38
  RoutingKey: SJC12P01PAS02
  X-Rate-Limit-Group: medium
  X-Rate-Limit-Limit: 40
  X-Rate-Limit-Remaining: 39
  X-Rate-Limit-Window: 60
  Content-Type: application/json; charset=utf-8
  Content-Length: 60
  Content-Language: en-US
}

thanks for any and all help

2 Answers
answered on Jan 18, 2022 at 8:06am  

.


 0
answered on Jan 17, 2022 at 9:06am  

as far as I can tell, I never got a successful post. can those success posts be the 'try it out' posts?


 0
on Jan 17, 2022 at 9:24am   •  0 likes

Then again, I believe that it's your PowerShell code that could convert the data in wrong format. Can you remove the plus sign from the number and try again.

on Jan 17, 2022 at 2:34pm   •  0 likes

I did test with the + and it made no difference, and the powershell code does work with HighVolume SMS, so I dont see why it would not work with regular SMS
This is how the powershell outputs to JSON

$AuthBodyTxt   = [pscustomobject]@{"from" = @{"phoneNumber"    = "+15555552434"};
                    "to"    = @(@{"phoneNumber"    = "+15555552586"});
                    "text"     = "$($message)"
}
 $AuthBodyTxt|ConvertTo-JSON -Depth 3
#------------
{
  "to": [
    {
      "phoneNumber": "+15555552434"
    }
  ],
  "from": {
    "phoneNumber": "+15555552586"
  },
  "text": "Test Message is blank"
}

I then just created the format without using ConvertTo-Json like this

 $nojson = "{
    $([char]34)to$([char]34): [{$([char]34)phoneNumber$([char]34): $([char]34)+15555552434$([char]34)}],
    $([char]34)from$([char]34): {$([char]34)phoneNumber$([char]34): $([char]34)+15555552586$([char]34)},
    $([char]34)text$([char]34): $([char]34)Test Message$([char]34)
  }"
  write-host $nojson
{
    "to": [{"phoneNumber": "+15555552434"}],
    "from": {"phoneNumber": "+15555552586"},
    "text": "The ARG is blank"
  }	

which gives the exact format shown in the reference guide. When search for unsupported media type

on Jan 17, 2022 at 2:37pm   •  0 likes

When searched for unsupported media type, I found someone saying that the Content-Type is not correct. This is what I have in my header

  $Header = @{"ContentType" = 'application/json'
            "accept" = "application/json"
            "authorization" = "Bearer $Bearer"
            }   

is that correct?

on Jan 17, 2022 at 5:31pm   •  0 likes

I found the error, Im not sure why it only affects this one POST request. In the header

"ContentType" = 'application/json'

should be

"Content-Type" = 'application/json'

Im not sure why it doesnt break on the HighVolume SMS, or any of the GET requests.

on Jan 17, 2022 at 11:25pm   •  0 likes

The 415 Unsupported Media Type issue seems to be thrown from powershell Invoke-RestMethod and Invoke-WebRequest where the Accept header and Content-Type is not set properly
These commandlets try to parse the response in xml (I think) because of these missing headers
The following code works for me
Could you please try this and confirm @ken-nye

Make sure to replace from, to and access-token valeus

$body = '{"to": [{"phoneNumber": "+188888888"}], "from": {"phoneNumber": "+199999999"}, "text": "Test SMS message from Platform server"}' | ConvertFrom-Json
$headers = @{Authorization = "Bearer $access-token"; Accept = "application/json"; 'Content-Type' = "application/json"}
$response = Invoke-RestMethod -Uri https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms -Method POST -Body ($body|ConvertTo-Json) -Headers $headers
on Jan 18, 2022 at 7:45am   •  1 likes

it is working now, as I stated in my last post, I have contenttype instead of content-type

answered on Jan 17, 2022 at 8:21am  

Based on your app analytics, I see you have 2 successful /sms POST calls, and other calls failed with 400, 401 and 513. Can you check and compare what did you change in your code that caused the failure?screen-shot-2022-01-17-at-81728-am.png


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us