Posting JSON to DocumentDB through REST API Posting JSON to DocumentDB through REST API json json

Posting JSON to DocumentDB through REST API


If you are trying to use Azure DocumentDB in a .NET application - you may find it easier to simply use the .NET SDK.

Assuming you'd really like to get the REST API working... taking a brief glance, I see a few things that need to be changed:

1.) The auth key looks off.

 var primary_key = Environment.GetEnvironmentVariable("APPSETTING_documentDB_primary_key"); // ... var data = "type=master&ver=1.0&sig=" + primary_key; // ... restRequest.AddHeader("Authorization", data);

Rather than passing in a master key, you will need to produce a hash signature. You can find documentation on auth here.

2.) The URI that you sending a POST request to looks a bit off.

var baseUrl = Environment.GetEnvironmentVariable("APPSETTING_documentDB_endpoint");// ...result = newClient.UploadString(baseUrl, "POST", "{\"id\":\"test1\"}");

You will need to construct the URI based on the resource you are trying to operate on. For example, the URI for creating a document should look something like:

https://{databaseaccount}.documents.azure.com/dbs/{_rid-db}/colls/{_rid-col}/docs