0

I am trying out rest-from-.net for Cosmos DB Table API.

Set the endpoint, masterKey , databaseId ,collectionId . I am using internal resource ids. Set x-ms-version as 2017-07-29.

Added the following before line 84.

client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");

Now, it looks like below:

client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2017-07-29");

//LIST all databases
verb = "GET";
resourceType = "dbs";
resourceId = string.Empty;
resourceLink = string.Format("dbs");

authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");

client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("ContentType", "application/json");

response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;

On the GetStringAsync call, I get 401.

HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).

Either the Authorization or x-ms-date header is not set. 401 is also returned when the Authorization header is set to an invalid authorization token.

Why is the authorization failing?

0

1 Answer 1

0

Though Querying Azure Cosmos DB resources using the REST API describes usage of REST for Cosmos DB, such use of REST is possible only for SQL API not for Gremlin, Cassandra or Table API. Unfortunately, the document doesn't mention that. Hence, the authorization was failing. Instead refer Table Service REST API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.