0

I'm scared to put this out there because it should be so easy and I am facing the same issue as the post here, here and here and I have tried each of the answers to no avail. Below is the current Resulting Input (redacted) and Related CodeView of the inputs.

The Result

{
"method": "post",
"headers": {
    "x-ms-documentdb-raw-partitionkey": "\"2020\""
},
"path": "/dbs/xxxx/colls/smtp/docs",
"host": {
    "connection": {
        "name": "/subscriptions/..."
    }
},
"body": {
    "category": [
        [
            "cat facts"
        ]
    ],
    "email": "example@test.com",
    "event": "processed",
    "id": "yada",
    "partitionKey": "\"2020\"",
    "sg_event_id": "yada yada",
    "sg_message_id": "yada",
    "smtp-id": "yada",
    "timestamp": 1604345542
}
}

The Code View

{
"inputs": {
    "body": {
        "category": [
            "@items('For_each')['category']"
        ],
        "email": "@items('For_each')['email']",
        "event": "@items('For_each')['event']",
        "id": "@items('For_each')['sg_message_id']",
        "partitionKey": "\"@{formatDateTime(utcNow(),'yyyy')}\"",
        "sg_event_id": "@items('For_each')['sg_event_id']",
        "sg_message_id": "@items('For_each')['sg_message_id']",
        "smtp-id": "@items('For_each')['smtp-id']",
        "timestamp": "@items('For_each')['timestamp']"
    },
    "headers": {
        "x-ms-documentdb-raw-partitionkey": "\"@{formatDateTime(utcNow(),'yyyy')}\""
    }
}

The error I'm getting is the usual one - PartitionKey extracted from document doesn't match the one specified in the header

I just can't see what I'm missing here now.

Thanks all.

1 Answers1

0

First, as Matias comments, check your partition key path.

Then, change this code "partitionKey": "\"@{formatDateTime(utcNow(),'yyyy')}\"", to "partitionKey": "@{formatDateTime(utcNow(),'yyyy')}", in your document.

It works fine on my side: enter image description here

Steve Johnson
  • 8,057
  • 1
  • 6
  • 17
  • @LeeAlderdice Since your partition key path is '/year', you need to change `"partitionKey": "\"@{formatDateTime(utcNow(),'yyyy')}\"", to "year": "@{formatDateTime(utcNow(),'yyyy')}",`. – Steve Johnson Nov 04 '20 at 08:59
  • I feel a tad silly but would like to thank you for your time. A new error to solve now but at least this one is solved. – Lee Alderdice Nov 04 '20 at 09:13