I am attempted to get a Document from DocumentDB using the REST API. I am using a partitioned Collection and therefore need to add the "x-ms-documentdb-partitionkey" header. If I add this, I get "Partition key abc is invalid". I can't find anywhere in the documentation that expects the key to be in specific format, but simply supplying the expected string value does not work. Does anyone know the expected format?
Asked
Active
Viewed 1.1k times
2 Answers
13
Partition key must be specified as an array (with a single element). For example:
x-ms-documentdb-partitionkey: [ "abc" ]

Aravind Krishna R.
- 7,885
- 27
- 37
-
Thanks! This is exactly what I needed! – Aiden Thompson Nov 04 '16 at 19:23
-
1[MS REST API documentation](https://learn.microsoft.com/en-us/rest/api/documentdb/querying-documentdb-resources-using-the-rest-api) doesn't document filtering by `partitionkey`, it does have a header attribute `x-ms-partition-key` which is ignored. Setting the header value `x-ms-documentdb-query-enablecrosspartition` to `true` will ignore partitions when querying. `x-ms-documentdb-partitionkey` does work - the gotcha is adding in the **brackets**, not just the partitionkey value. – SliverNinja - MSFT Mar 24 '17 at 18:43
-
Hi Aravind, do you know how the partition key should be specified inside a cosmos Stored Procedure? I've been trying all different combinations but not having any luck. posted a question here https://stackoverflow.com/questions/48900680/400-error-when-upsert-using-cosmos-sp – Illuminati Feb 21 '18 at 07:54
-
this must be passed in as a request header to the stored procedure. A sproc operates within the scope of a single partition key – Aravind Krishna R. Feb 21 '18 at 17:07
-
My partition key value has been named in non-english. It seems to be failed to get the document. Is there any solution? – FVBn Jun 04 '21 at 09:26
2
Partition key for a partitioned collection is actually the path to a property in DocumentDB. Thus you would need to specify it in the following format:
/{path to property name} e.g. /department
From Partitioning and scaling in Azure DocumentDB
:
You must pick a JSON property name that has a wide range of values and is likely to have evenly distributed access patterns. The partition key is specified as a JSON path, e.g. /department represents the property department.
More examples are listed in the link as well.

Gaurav Mantri
- 128,066
- 12
- 206
- 241