title: Using REST for CRUD operations in Azure Cosmos DB
body: <p>I am trying do CRUD operations on Azure Cosmos DB using REST. As per the link-
  <a href="https://docs.microsoft.com/en-us/rest/api/documentdb/create-a-document" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/documentdb/create-a-document</a>
  I have created my payload and trying to test it using Restman in Opera browser. Below is my payload details-</p>
  
  <p><strong>Headers</strong></p>
  
  <pre><code>Authorization       ***************************
  
  Content-Type        application/query+json
  
  x-ms-date           Tue, 05 Dec 2017 16:49:31 GMT
  
  x-ms-session-token  Session
  
  x-ms-version        2017-02-22
  </code></pre>
  
  <p><strong>Body</strong></p>
  
  <pre><code>id        sg4c828f-31f8-4db4-8e7c-e8bdff222dsg
  
  value     {     "id": "AndersenFamily",     "LastName": "Andersen",     "Parents": [       {         "FamilyName": null,         "FirstName": "Thomas"       },       {         "FamilyName": null,         "FirstName": "Mary Kay"       }     ],     "Children": [       {         "FamilyName": null,         "FirstName": "Henriette Thaulow",         "Gender": "female",         "Grade": 5,         "Pets": [           {             "GivenName": "Fluffy"           }         ]       }     ],     "Address": {       "State": "WA",       "County": "King",       "City": "Seattle"     },     "IsRegistered": true   }
  </code></pre>
  
  <p>The auth-token which is put in the request header has been generated in C# using below code (as per the sample in the link mentioned above)-</p>
  
  <pre><code>string GenerateAuthToken(string verb, string resourceType, string resourceId, string date, string key, string keyType, string tokenVersion)
  {
      var hmacSha256 = new System.Security.Cryptography.HMACSHA256 { Key = Convert.FromBase64String(key) };
  
      verb = verb ?? "";
      resourceType = resourceType ?? "";
      resourceId = resourceId ?? "";
  
      string payLoad = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}\n{1}\n{2}\n{3}\n{4}\n",
              verb.ToLowerInvariant(),
              resourceType.ToLowerInvariant(),
              resourceId,
              date.ToLowerInvariant(),
              ""
      );
  
      byte[] hashPayLoad = hmacSha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(payLoad));
      string signature = Convert.ToBase64String(hashPayLoad);
  
      return System.Web.HttpUtility.UrlEncode(String.Format(System.Globalization.CultureInfo.InvariantCulture, "type={0}&amp;ver={1}&amp;sig={2}",
          keyType,
          tokenVersion,
          signature));
  }
  </code></pre>
  
  <p>This is how pass the parameters-</p>
  
  <pre><code>GenerateAuthToken("GET", "dbs", "dbs/ToDoList", "Tue, 05 Dec 2017 16:49:31 GMT", PARENT_KEY, "master", "1.0");
  </code></pre>
  
  <p>So when I make the POST request to the URL- </p>
  
  <pre><code>https://&lt;account_name&gt;.documents.azure.com:&lt;port&gt;/dbs/DCEAAA==/colls/DCEAAIcEVAA=/docs
  </code></pre>
  
  <p>I get below response-</p>
  
  <blockquote>
    <p>{
        "code": "Unauthorized",
        "message": "The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol,
    and check the key being used. Server used the following payload to
    sign: 'post\ndocs\ndceaaicevaa=\ntue, 05 dec 2017 16:49:31
    gmt\n\n'\r\nActivityId: 7565996c-d008-438d-a1e9-744d4871948a,
    Microsoft.Azure.Documents.Common/1.19.121.4" }</p>
  </blockquote>
  
  <p>I am clueless what exactly is going wrong here. Please let me know if someone have any ideas. For any clarifications please let me know.</p>
  
  <p><strong>Edit:</strong> Adding the Restman screenshot below-
  <a href="https://i.stack.imgur.com/pwsx2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pwsx2.jpg" alt="enter image description here"></a></p>