3

I have created event grid topic in azure using event schema = "Event Grid Schema".

The next steps for me is trying to send messages to that event grid topic so the subscribers can do something when the message has been successfully received in event grid topic.

However, I had a problem when sending the message to event grid topic. It always reject my JSON request with error "Required property 'subject' was not set. even tough, I have explicitly set the subject in my JSON post body.

I have also add 'aeg-sas-key' value in header for authentication purposes.

Here is an example of my JSON format:

{
    "id": "19291",
    "subject": "myapp/vehicles/motorcycles",
    "topic": "VehicleData",
    "eventType": "statusupdated",
    "eventTime": "2019-05-12T18:41:00.9584103Z",
    "data":{
         "firstName": "Jason",
         "postalAddress": "xyz"
    },
    "dataVersion": "1.0",
    "metadataVersion": "string"
  }

and Here is the output:

{
    "error": {
        "code": "BadRequest",
        "message": "Required property 'subject' was not set. Report '433759ee-6570-466e-ae12-a6dc5fccbfe1:5/14/2019 4:01:32 AM (UTC)' to our forums for assistance or raise a support ticket.",
        "details": [
            {
                "code": "InputJsonInvalid",
                "message": "Required property 'subject' was not set. Report '433759ee-6570-466e-ae12-a6dc5fccbfe1:5/14/2019 4:01:32 AM (UTC)' to our forums for assistance or raise a support ticket."
            }
        ]
    }
}

Any idea why it always ask for subject even tough I have provided the subject in my JSON?

Emma
  • 27,428
  • 11
  • 44
  • 69
Arif Liminto
  • 31
  • 1
  • 2

2 Answers2

0

Based on the docs:

Post to custom topic for Azure Event Grid

Azure Event Grid event schema

use the following payload:

    [
      {
        "id": "19291",
        "subject": "myapp/vehicles/motorcycles",
        "topic": null,
        "eventType": "statusupdated",
        "eventTime": "2019-05-12T18:41:00.9584103Z",
        "data": {
          "firstName": "Jason",
          "postalAddress": "xyz"
          },
        "dataVersion": "1.0",
        "metadataVersion": null
      }
   ]
Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
  • did exactly like that , but still have the same problem. "Required property 'subject' was not set." – Arif Liminto May 14 '19 at 05:10
  • how did you create this custom topic? using the Azure portal? The error message looks like from the inputSchemaMapping where your payload doesn't have a property for the 'subject' mapping. – Roman Kiss May 14 '19 at 06:17
  • I have created custom topic using azure portal, however after digging around, i end up adding this attribute in my JSON `"source": "xxxxxxxxxx#newStatusUpdated"`, and the status returns 200 and remove the subject attribute. also instead of using event grid schema, I've changed it to cloud event schema – Arif Liminto May 14 '19 at 08:11
  • Please, update your question for more details what did you made with the custom topic resource. – Roman Kiss May 14 '19 at 13:59
0

If you created the topic using the Azure Portal, did you somewhere specify the inputSchemaMapping?

According to the specifications here: https://learn.microsoft.com/en-us/rest/api/eventgrid/topics/createorupdate

You need to specify a inputSchemaMapping when opting for the CustomEventSchema.

Witte
  • 1
  • I have created custom topic using azure portal, however after digging around, i end up adding this attribute in my JSON `"source": "xxxxxxxxxx#newStatusUpdated"`, and the status returns 200 and remove the subject attribute. also instead of using event grid schema, I've changed it to cloud event schema. and it seems like behind the scene : azure parse the source attribute and looking for #word to be treated as subject? – Arif Liminto May 14 '19 at 08:17