cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2903
Views
1
Helpful
6
Replies

The remote server returned an error: (415) Unsupported Media Type

vbj1995
Level 1
Level 1

I am trying to get webex calling "call history" report using API but keep getting "The remote server returned an error: (415) Unsupported Media Type error". The sample powershell code is as follows:-

$token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

$headers = @{
"Authorization" = "Bearer $token"
}

$webexUrl = "https://webexapis.com/v1/telephony/calls/history?type=missed"

Invoke-restmethod -Method get -Uri $webexUrl -Headers $headers

Error:

Invoke-restmethod : The remote server returned an error: (415) Unsupported Media Type.
At line:1 char:1
+ Invoke-restmethod -Method get -Uri $webexCHUrl -Headers $headers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invok
e-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeR
estMethodCommand

6 Replies 6

Gasper A
Cisco Employee
Cisco Employee

@vbj1995 below is an example that you can build from; I should also mentioned that I used Postman code covert tool to generate the powershell code below;

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer YmM5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

$response = Invoke-RestMethod 'https://webexapis.com/v1/telephony/calls/history?type=missed' -Method 'GET' -Headers $headers
$response | ConvertTo-Json

 

dstaudt
Cisco Employee
Cisco Employee

The code doesn't appear to be specifying the return content format - can you add a header for "Accept" = "application/json" ?

I have tried using Accept parameter in the header still it is throwing 415
error. Can you please help us with the correct format to use Accept and
content-type in the code mentioned.

Tested in Powershell using the following and it did work correctly.

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer OTdjYjA5N2EtYWN........")

$response = Invoke-RestMethod 'https://webexapis.com/v1/telephony/calls/history?type=missed' -Method 'GET' -Headers $headers
$response | ConvertTo-Json

 

Looks like the API is _requiring_ "Content-Type: application/json" - it returns 415 if it's missing - however I don't think it should do that, as this is a GET request which does not include a body.

I'll see about opening a ticket on this, as IMHO it's an error.

Ticket # is 111458

I believe you can contact Webex developer support and request to be CC'd on the ticket to get any updates on the issue.