arcus-azure / arcus.eventgrid

Azure Event Grid development in a breeze
https://eventgrid.arcus-azure.net/
MIT License
17 stars 6 forks source link

400 Bad Request #145

Closed jcoffeng closed 3 years ago

jcoffeng commented 3 years ago

This is probably a rookie mistake. I get a Http 400 exception when posting to PublishAsync(@event) (docs link)

Flurl.Http.FlurlHttpException: 'Call failed with status code 400 (Unexpected token when reading JSON. Expected: StartArray, actual: StartObject. Report 'c28fd24a-bf33-40e1-b01e-9f86ec0e4bd1:1:9/23/2020 2:38:00 PM (UTC)' to our forums for assistance or raise a support ticket.): POST https://

How do I go about resolving this?

tomkerkhove commented 3 years ago

Can you provide some more information on what it looks like what you are posting and such please?

stijnmoreels commented 3 years ago

That looks like the exception of a previous version where we only allowed receiving JSON arrays and not single objects. Can you please provide us with the version of the package you're using? Thanks.

jcoffeng commented 3 years ago

Stijn, you may be right, I am using Arcus.EventGrid.All 3.0.0. Is this package and its version correct? Tom, here is the request:

{
  "specversion": "1.0",
  "type": "NewCarRegistered",
  "source": "https://eventgrid.arcus-azure.net/",
  "id": "3a1ddf76-834a-4a07-b745-d37fb121562c",
  "time": "2020-09-25T09:35:12.2635631Z",
  "subject": "/cars/1-TOM-337",
  "data": {},
  "datacontenttype": "application/json"
}
tomkerkhove commented 3 years ago

Can you provide some info on how you try to publish it so that @stijnmoreels can have a look please?

jcoffeng commented 3 years ago

@tomkerkhove I tried PublishManyAsync a minute ago and I got Call failed with status code 400 (Unexpected property 'specversion' found in JSON. Am using .Net Core 3.1 console application at the moment. Is this information sufficient, @stijnmoreels ?

tomkerkhove commented 3 years ago

Can you just provide the code snippet please?

stijnmoreels commented 3 years ago

@tomkerkhove I tried PublishManyAsync a minute ago and I got Call failed with status code 400 (Unexpected property 'specversion' found in JSON. Am using .Net Core 3.1 console application at the moment. Is this information sufficient, @stijnmoreels ?

Hmm, that seems like some mismatch with schema versions. In an older version of CloudEvents, the specVersion was located differently. Are you sure that the version you're using to serialize/publish/use... your CloudEvents models in your code, matches the schema version in the Azure EventGrid resource?

jcoffeng commented 3 years ago
 string licensePlate = "1-TOM-337";
            string eventSubject = $"/cars/{licensePlate}";
            string eventId = Guid.NewGuid().ToString();

            var @event = new CloudEvent[2] { new CloudEvent(
                CloudEventsSpecVersion.V1_0,
                "NewCarRegistered",
                new Uri("https://eventgrid.arcus-azure.net/"),
                eventSubject,
                eventId)
            {
                Data = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            }, new CloudEvent(CloudEventsSpecVersion.V1_0,
                "NewCarRegistered",
                new Uri("https://eventgrid.arcus-azure.net/"),
                eventSubject,
                eventId)
            {
                Data = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            }
            };

            await eventGridPublisher.PublishManyAsync(@event);

@tomkerkhove code snippet above

tomkerkhove commented 3 years ago

@stijnmoreels will look into this but you should not be using the same event ID across multiple events (although that's not the issue ere)

stijnmoreels commented 3 years ago

@tomkerkhove I tried PublishManyAsync a minute ago and I got Call failed with status code 400 (Unexpected property 'specversion' found in JSON. Am using .Net Core 3.1 console application at the moment. Is this information sufficient, @stijnmoreels ?

Hmm, that seems like some mismatch with schema versions. In an older version of CloudEvents, the specVersion was located differently. Are you sure that the version you're using to serialize/publish/use... your CloudEvents models in your code, matches the schema version in the Azure EventGrid resource?

Have you already take a look at this? It doesn't seem anything wrong with the code as it's almost an exact copy of our tests. My guess is on the event schema in your Azure EventGrid resource.

tomkerkhove commented 3 years ago

A-ha, yes that will most probably be it - What is the configuration of your Azure Event Grid topic @begonias ?

jcoffeng commented 3 years ago

@tomkerkhove it was erroneous, should be

"properties": { "inputSchema": "CloudEventSchemaV1_0",

and inputSchema contained value EventGridSchema.

Now it works like a charm.

tomkerkhove commented 3 years ago

Great to hear and sorry for the slow support!