10-12-2022 04:33 AM
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
10-17-2022 02:36 PM
@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
10-12-2022 10:56 AM
The code doesn't appear to be specifying the return content format - can you add a header for "Accept" = "application/json" ?
10-12-2022 10:15 PM
10-18-2022 05:50 AM
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
10-18-2022 07:36 AM
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.
10-18-2022 07:50 AM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide