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).
I have Contributor role on the Azure Cosmos DB account.
I have gone through this post on stack overflow.
Querying Azure Cosmos DB resources using the REST API is for SQL API and not for Table API. But I have followed the relevant mentioned parts.
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.
- After reading Diagnose and troubleshoot Azure Cosmos DB unauthorized exceptions, I have also tried using a regenerated Read-Write Primary Key.
Why is the authorization failing?