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
as far as I can tell, I never got a successful post. can those success posts be the 'try it out' posts?
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.
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
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?
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.
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
it is working now, as I stated in my last post, I have contenttype instead of content-type
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