0
votes

I have a partitioned collection in Cosmos DB. I'm attempting to execute a stored procedure within this collection using Postman as documented here https://docs.microsoft.com/en-us/rest/api/documentdb/execute-a-stored-procedure. When I do this, I encounter the following error:

{
    "code": "BadRequest",
    "message": "PartitionKey value must be supplied for this operation.\r\nActivityId: 0000000-0000-0000-0000-000000000000000, Microsoft.Azure.Documents.Common/1.19.162.2"
}

I have a partition key that I'm sending as a parameter to the stored procedure, and subsequently using in the WHERE clause of the query within the procedure, but the API seems to expect the partition key to be passed in some other fashion, i.e., request header?

When using the C# Document DB SDK, the partition key is set as a RequestOption as follows:

var storedProcedureUri = UriFactory.CreateStoredProcedureUri("MyDB", "MyCol", "MyProc");
var requestOptions = new RequestOptions { PartitionKey = new PartitionKey(myPartitionKey) };
var procedureResponse = await Client.ExecuteStoredProcedureAsync<MyObjType>(storedProcedureUri, requestOptions);
var document = procedureResponse.Response;

return document;

I'm not seeing where/how this request option can be set when executing the procedure from basic web client.

1
I’ve seen this in some documentation set as a key on a request header x-ms-documentdb-partitionkey - not sure if it’ll work?Danny Dainton

1 Answers

2
votes

PartitionKey is required as a request header, along with a few others:

client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2017-02-22");
client.DefaultRequestHeaders.Add("x-ms-documentdb-partitionkey",
    new PartitionKey(signingDocumentId).ToString());

See here for more info: https://docs.microsoft.com/en-us/rest/api/documentdb/common-documentdb-rest-request-headers