deko deko - 2 months ago 21
reST (reStructuredText) Question

Azure Table Service REST API: JSON format is not supported

I'm trying to request a line from Azure Table Storage using the REST API and C++, but always got the following error:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<cod_e>JsonFormatNotSupported</cod_e>
<message xml:lang="en-US">JSON format is not supported.
RequestId:0ccb3b9b-0002-0029-3389-0d2fa1000000
Time:2016-09-13T06:39:13.3155742Z</message>
</error>


Here is my request:

GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature>


Here how I fill request headers, as from https://msdn.microsoft.com/en-us/library/dd179428.aspx:

std::string sharedAccessSignature("<sharedsignature>");
std::string dateTime(GetDateTime());
std::string stringToSign(dateTime + "\n/" + account + "/" + "<mytable>");
std::string request("(PartitionKey='<mypartition>',RowKey='<myrow>')");
stringToSign += request;
std::string signatureString(HMACSHA256(stringToSign, sharedAccessSignature));

headers["Authorization"] = "SharedKeyLite " + account + ":" + signatureString;
headers["DataServiceVersion"] = "3.0;NetFx";
headers["MaxDataServiceVersion"] = "3.0;NetFx";
headers["x-ms-version"] = "2015-12-11";
headers["x-ms-date"] = dateTime;
headers["Accept"] = "application/json;odata=verbose";
headers["Accept-Charset"] = "UTF-8";


The table exists and is not empty.

Please advise what's wrong?

Update 1

Removing
sharedsignature
from request, i.e.
GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')
leads to the same result.

Removing
Authorization
header from the request leads to the same result too.

Update 2

Putting
https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature>
in a browser produces a valid response, but in Atom format.

<?xml version="1.0" encoding="utf-8"?>
<entry
xml:base="https://<myaccount>.table.core.windows.net/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:etag="W/&quot;datetime'2016-09-13T05%3A29%3A51.211538Z'&quot;">
<id>https://<myaccount>.table.core.windows.net/<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')</id>
<category term="<myaccount>.<mytable>" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="<mytable>" href="<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')" />
<title />
<updated>2016-09-13T11:25:19Z</updated>
<author><name /></author>
<content type="application/xml">
<m:properties>
<d:PartitionKey><mypartition></d:PartitionKey>
<d:RowKey><myrow></d:RowKey>
<d:Timestamp m:type="Edm.DateTime">2016-09-13T05:29:51.211538Z</d:Timestamp>
<d:Score m:type="Edm.Int32">1050</d:Score>
</m:properties>
</content>
</entry>


Update 3

Investigation situation using
curl
I found that adding
Accept: application/json;odata=fullmetadata
to the request headers leads to the error above. Default
Accept */*
in headers produces valid Atom response.

Answer

Finally, got it!
The issue was in my shared signature.
While looking at it I found sv=2012-02-12 part, and assumed, that it means API version. The version, before JSON support was introduced! I created a new shared signature and finally got JSON with the following curl command.
curl -v -H "Accept: application/json;odata=nometadata" -H "x-ms-version: 2015-12-11" "https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<mysharedsignature>"

So, for everyone, who face the same issue in the future: please check your signature first!