Getting a JsonException when deserializing the payload from the v2.analytics.conversation.aggregate webhook. The docs say the structure is straightforward, but the metrics array is throwing a fit. Here’s the snippet I’m using in the Azure Function:
var response = await client.PostAsJsonAsync("https://example.com/webhook", payload);
var json = await response.Content.ReadAsStringAsync();
var analytics = JsonSerializer.Deserialize<AnalyticsEnvelope>(json);
The error is: The JSON value could not be converted to System.Int32. Path: $.metrics[0].count. LineNumber: 0. BytePositionInLine: 15.
Looking at the raw JSON from the debug trace:
{
"id": "conv-123",
"metrics": [
{
"name": "duration",
"count": 1.5,
"avg": 1.5
}
]
}
The count field is coming as a float (1.5), but my C# model has it as int. The documentation for the aggregate endpoint states: “Metric values are normalized to integers for counting events.” It doesn’t mention floats. I’ve tried adding [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] but that doesn’t help with the int/float mismatch. Should I be casting manually, or is there a specific SDK method I’m missing? The event type is definitely v2.analytics.conversation.aggregate.