Webhooks JSON nested Object missing BEGIN_OBJECT

Ok I'm at my whits end here...

I'm trying to send a webhook with json data.

The webhook json is defined as follows:

{
  "type": "{{type}}",
  "sub_type": "{{sub_type}}",
  "alert": "{{alert}}",
  "data": "{{data}}"
}

the "data" part is a nested JSON object: example:

{"amount" : 3.3, "scheduled" false}

(the nested object changes what it sends based on where/when in my code it gets sent)

I've also tried formatting the webhook like this:

{
  "type": "{{type}}",
  "sub_type": "{{sub_type}}",
  "alert": "{{alert}}",
  "data": "{{{data}}}"
}

Here's the String I'm sending:

String mess = "{\"type\":1,\"sub_type\":7,\"alert\":true,\"data\":{\"amount\":3.3,\"scheduled\":false}}";

The console says it sent:

{"data":"{\"type\":1,\"sub_type\":7,\"alert\":true,\"data\":{\"amount\":3.3,\"scheduled\":false}}","ttl":"60","published_at":"2016-06-29T17:13:07.195Z","coreid":"2d0020001547343339383037","name":"ahomeevent"}

My server keeps sending me an error saying it's missing the BEGIN_OBJECT

"Expected BEGIN_OBJECT but was STRING at line 1 column 51 path $.data"

I think this is an unfortunate combination that can’t exactly be implemented right now in webhooks. The reason is that you can’t insert a non-string in an object. So you can’t just insert data like that. Also, you can’t insert things like numbers and booleans, either.

The closest you can get is:

{
  "type": "{{type}}",
  "sub_type": "{{sub_type}}",
  "alert": "{{alert}}",
  "data": { "amount":"{{data.amount}}", "scheduled":"{{data.scheduled}}" }
}

The amount and scheduled will both be strings instead of a number and a boolean, but some servers can deal with that. If not, you’ll be kind of stuck for now.

The ability to insert non-strings is a planned feature, but it’s not available yet.

2 Likes

Ah… So I HAVE to declare what will be in the Data object in the webhook?

I was trying to dynamically build that part so I could re-use webhooks and let my server figure it out… I guess that can’t be done?

Drat…

So that DOES appear to be the issue- so at least I’m partway there… now to deal with the pesky string values.

Boo for not being able to reuse my webhooks as much as I’d like. :frowning:

A post was split to a new topic: Webhook [Object object] issue