Powershell Invoke RestMethod error 415 Unsupported Media Type


I’m trying to execute Azure Table Storage API using Powershell Invoke-RestMethod but it returns 415 error.

Here’s Powershell code:

Remote server retunrned error:

詳細: GET
with 0-byte payload 詳細: received 4841-byte response of content type
application/json; charset=utf-8 詳細: POST
https://telemaapimlog.table.core.windows.net/reporttable with -1-byte
payload Invoke-RestMethod : リモート サーバーがエラーを返しました*: (415) Unsupported
Media Type 発生場所 C:\Users\sasaki.hikaru\Desktop\repot.ps1:83 文字:1
+ Invoke-RestMethod -Method POST -Uri $table_url -Headers $table_headers -Body $js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest)
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I have read some similar problems in this site but they are no content-type or json description issues mostly so I assume that there are no problems in my code.

Anybody have ideas? Please help me.


Interesting problem. The reason you’re getting this error is because you have not specified the format of response data i.e value for Accept request header. Because you have not specified this value, storage service treats its value as XML which is not supported for the storage service version that you have specified.

Once you include this Accept header (and specify value for PartitionKey and RowKey in your $body), things should work just fine.

Here’s the code that I wrote:


Powershell Invoke RestMethod error 415 Unsupported Media Type by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply