Cosmos DB SQL without postman

Raja 86 Reputation points
2021-07-07T15:27:24.227+00:00

Hi Team,
I'm using CosmosDB to store the JSON documents. The database gives inbuilt SQL REST API feature to query the database.

With this inbuilt feature I'm able to query data perfectly using GET and POST methods. This is working perfectly alright using "Postman". Now I want to try this for real consumer, which is not working.
I've imported the cosmosdb queries from git (https://github.com/MicrosoftCSA/documentdb-postman-collection) which is recommended by Microsoft in one of its tutorials .

Now when I looked this in detail, I see that Postman is using "Pre-request Script" where it is modifying

var mastKey = postman.getEnvironmentVariable("DocumentDBMasterKey");  
master key - var key = CryptoJS.enc.Base64.parse(mastKey);  
var signature = CryptoJS.HmacSHA256(text, key);  
var base64Bits = CryptoJS.enc.Base64.stringify(signature);  
var MasterToken = "master";  
var TokenVersion = "1.0";  
auth = encodeURIComponent("type=" + MasterToken + "&ver=" + TokenVersion + "&sig=" + base64Bits)  

With this pre-script it works perfectly alright. But as a consumer how would I consume this?

  1. Should consumer really bother about this script or he should just provide authentication token and required headers and the API should just work?
  2. If consumer really need to write this pre-script, where would he write?

Any help would be highly appreciated.

Thanks

112617-cosmosdbsqlpostman-collection.txt

Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.


1 answer

Sort by: Newest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    5 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.