1
votes

I always get 401 when I try to execute a DELETE verb against a DocumentDB collection. POST for queries/inserts/updates works fine, so I am sure that my code that calculates the authorization token is correct. What I am not sure however is what I should pass for the resource id and resource type.

payLoad := LowerCase(Verb) + #10+
           LowerCase(resourceType) + #10+
           LowerCase(resourceId) + #10+
           LowerCase(utc_date) + #10 +
           '' + #10; //instead of the "date" header

For the POST (which works), I use

"docs" and "dbs/mydb/mycol/licenses"

For DELETE I use the value of the "_self" property for the url of the doc to be deleted. I tried just about any combination of resource type and resource id I could think of:

docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs
docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==
docs    dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==/
docs/icUoAKizCgADAAAAAAAAAA==   dbs/icUoAA==/colls/icUoAKizCgA=/docs
docs/icUoAKizCgADAAAAAAAAAA==   dbs/icUoAA==/colls/icUoAKizCgA=/docs/icUoAKizCgADAAAAAAAAAA==
etc.

DELETE however always fails with 401. Do I need to use something different?

Thank you!

1
Looking at the Delete Document REST API documentation - msdn.microsoft.com/en-us/library/azure/mt489087.aspx, I noticed that it expects the document name instead of system assigned resource id while you're using the resource id. Could that be the reason for this error you're getting? - Gaurav Mantri
But what is "name"? It is definitely not an id (there were quite a few discussions where people complain that you cannot use id for a deletion), so it can be either "_self" or "_rid". - Dmitry Streblechenko
From the examples I have seen, my take is that "name" is the "id" that you assign to the document in your collection. - Gaurav Mantri
Yes, but I read it that it is only available on the .Net SDK level and the libraries for other languages. If I use a url with an id (e.g. 'dbs/mydb/colls/mycol/docs /cc0d4caabc714aac976c9d0a2e9243ed'), I get back 400 error - {"code":"BadRequest","message":"Request url is invalid.\r\nActivityId: 91f46993-6bbe-4d5a-a130-6825df212263"}. - Dmitry Streblechenko
@DmitryStreblechenko : I remember having similar issues with deleting a db - I do not remember on top of my head but here is a link to my doc db rest endpoint playbook sort where I put in a few lines of code to save myself some time for future reference github.com/jayalakshmis/IDIOSYNCRASIES/tree/master/… - this might help you - Jaya

1 Answers

2
votes

There's two kinds of requests you can make to DocumentDB. One is based on the "id" property that you define, and one based on the internal resource id ("_rid"). When you're using "id", you need to use the entire link for generating the authorization token, so for delete it would look like

delete
docs
dbs/mydb/colls/mycol/docs/cc0d4caabc714aac976c9d0a2e9243ed
sun, 21 aug 2016 20:00:00
 //newline

If you're using the internal resource ID, then you just pass in the "_rid" of the document you're trying to delete, for example

delete
docs
icuoakizcgadaaaaaaaaaa== //lowercase
sun, 21 aug 2016 20:00:00
 //newline

One thing which might help debugging these is looking at the response body that's returned with the 401. It should contain an error message telling you the payload that the server expected.