Jeroen Wyseur
Jeroen Wyseur

Reputation: 3553

change the header Content-Type to application/cloudevents+json when publishing to event grid

I'm using the trigger "When a HTTP request is received" to then publish multiple events to the event grid using the "Publish Event" action. The For loop works fine to split up the JSON that gets in and create the event to publish but still that publish fails with

{
  "error": {
    "code": "UnsupportedMediaType",
    "message": "The Content-Type header is either missing or it doesn't have a valid value. The content type header must either be application/cloudevents+json; charset=utf-8 or application/cloudevents-batch+json; charset=UTF-8. Report 'edf36bbd-9221-4882-8a29-2264ffb16d72:3:3/6/2020 2:18:20 PM (UTC)' to our forums for assistance or raise a support ticket.",
    "details": [
      {
        "code": "InvalidContentType",
        "message": "The Content-Type header is either missing or it doesn't have a valid value. The content type header must either be application/cloudevents+json; charset=utf-8 or application/cloudevents-batch+json; charset=UTF-8. Report 'edf36bbd-9221-4882-8a29-2264ffb16d72:3:3/6/2020 2:18:20 PM (UTC)' to our forums for assistance or raise a support ticket."
      }
    ]
  }
}

I assume that the header from the input is used when publishing so I tried to change the header when publishing by changing the header in the Publish_Event block as follows (directly in code view as it is not supported in the UI) so I get the following (headers part is added):

"Publish_Event": {
    "inputs": {
        "body": [
            {
                "data": "@items('For_each_2')",
                "eventType": "company-location",
                "id": "ID : @{items('For_each')['businessId']}",
                "subject": "Company Location changed"
            }
        ],
        "headers": {
            "Content-Type": "application/cloudevents+json; charset=utf-8"
        },
        "host": {
            "connection": {
                "name": "@parameters('$connections')['azureeventgridpublish']['connectionId']"
            }
        },
        "method": "post",
        "path": "/eventGrid/api/events"
    },
    "runAfter": {},
    "type": "ApiConnection"
}

But this is not working neither. Didn't find an action to make the change.

My full flow looks like this : app logic flow

and as test data I have the following JSON I use to send with postman (a bit simplified):

[
    {
        "id": 3603,
        "businessId": "QQTADOSH",
        "locations": [
            {
                "id": 5316,
                "businessId": "A-yelr3g"
            },
            {
                "id": 5127,
                "businessId": "A-c7i8gd"
            },
            {
                "id": 5403,
                "businessId": "A-fjdd2y"
            },
            {
                "id": 6064,
                "businessId": "A-rqvhz8"
            }
        ]
    },
    {
        "id": 3118,
        "businessId": "Cr11_Macan_111qa",
        "locations": [
            {
                "id": 4563,
                "businessId": "A-3bv860"
            }
        ]
    }
]

Upvotes: 0

Views: 3155

Answers (1)

PramodValavala
PramodValavala

Reputation: 6647

Looks like the Official Event Grid Publish Connector doesn't support Cloud Events Schema.

You can set the topic to accept Event Grid Schema but I believe this is possible only at the time of creation.

Its best to open a feature request on UserVoice to add support for this and in the meantime, a workaround would be to use an HTTP Action to Post to Custom Topic instead.

But do note that the workaround would involve building the event payload to send (and things like fetching the access key from Key Vault instead of storing it in your workflow directly).

Upvotes: 1

Related Questions