0
votes

I ran into this error while building a Logic App in Azure. The solution to this DocumentDB REST API: PartitionKey extracted from document doesn't match is not working.

My logic app receives a POST request with the raw JSON data, and then sends it to a Cosmos "Create or Update Document" step. In there, I am able to specify my DB, and for my inputs, I have body and headers like so:

...
"inputs": {
   "body": "@triggerBody()",
   "headers": {
      "x-ms-documentdb-partitionkey": "@triggerBody()?['date']"
   },
   ...
}
...

My JSON data looks like this:

{
  "id": "20190106",
  "date": "20190106",
  ...
}

In the error output, it literally shows my PartitionKey as 20190106, so the @triggerBody()?['date'] seems to have worked.

Any ideas?

3

3 Answers

0
votes

Don't forget to add Content-Type: application/json in the Post request.(mentioned in this thread)

Cosmos DB connector:

enter image description here

Post Request:

enter image description here

Output:

enter image description here

0
votes

If your partition key is date, then try passing the value of date [“20190106"] (use the square brackets) in the partition key header. This worked for me 2 days ago using Rest API for CosmoDb.

0
votes

The answer is that Logic Apps do not support the Mongo API. Yes, there's a workaround, as in the Logic App can pass data from one endpoint to a serverless function that then writes to Mongo.

Problems inserting document with Mongodb and Logic Apps