Cosmos DB Document DB REST APIs

Srinivasulu Valleti 26 Reputation points
2023-11-14T04:24:50.94+00:00

Hi

I am trying to use Cosmos DB APIs and create a new Item by following below API document

https://learn.microsoft.com/en-us/rest/api/cosmos-db/create-a-document

I got below Error.

My partition Key is /tid

I have given the header x-ms-documentdb-partitionkey = ["tid"]

If any one sees this . Please suggest.

{
    "code": "BadRequest",
    "message": "Message: {\"Errors\":[\"PartitionKey extracted from document doesn't match the one specified in the header. Learn 
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,504 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 14,196 Reputation points Microsoft Employee
    2023-11-14T04:55:01.7033333+00:00

    Hi Srinivasulu Valleti •,

    Welcome to Microsoft Q&A forum.

    As I understand, you are getting error when creating new item in Cosmos DB as PartitionKey extracted from document doesn't match the one specified in the header.

    When creating a new container make sure use "/" before the key name.

    Also, make sure to pass the value of partition key instead of name of partition key.

    Refer to the similar post with solutions which might help in your case: https://stackoverflow.com/questions/58121736/partitionkey-extracted-from-document-doesnt-match-the-one-specified-in-the-head

    Let us know if this helped.

    Thanks

    0 comments No comments