Search code examples
jsonwebhookszohozoho-delugedeluge

How to access key's value from nested JSON in body of Incoming Webhook on Zoho Deluge


Attempting to use MailChimp outbound Webhook to sync Zoho Contacts via Zoho's Incoming Webhook functionality and can't figure out how to access the value of "email" from the "body" sent to Incoming Webhook.

body being sent to webhook=

{"body":"{ \"type\": \"subscribe\", \"fired_at\": \"2009-03-26 21:35:57\", \"data\": { \"id\": \"8a25ff1d98\", \"list_id\": \"a6b5da1054\", \"email\": \"[email protected]\", \"email_type\": \"html\", \"ip_opt\": \"10.20.10.30\", \"ip_signup\": \"10.20.10.30\" \"merges\": { \"EMAIL\": \"[email protected]\", \"FNAME\": \"Mailchimp\", \"LNAME\": \"API\", \"INTERESTS\": \"Group1,Group2\" } } }"}

Simple code I am using to cast the string body to JSON.

responseBody = body.getJSON("body");
info "responseBody= "+ responseBody;

EXAMPLE OUTPUT: body= { "type": "subscribe", "fired_at": "2009-03-26 21:35:57", "data": { "id": "8a25ff1d98", "list_id": "a6b5da1054", "email": "[email protected]", "email_type": "html", "ip_opt": "10.20.10.30", "ip_signup": "10.20.10.30" "merges": { "EMAIL": "[email protected]", "FNAME": "Mailchimp", "LNAME": "API", "INTERESTS": "Group1,Group2" } } }

I am assuming I need to cast the body string to JSONand then access using GetJSON, but everything I try is returning NULL.

How can I get the value of Email into a variable to use in my deluge function?

Related: https://www.zoho.com/deluge/help/functions/common/getjson.html https://www.zoho.com/deluge/help/functions/text.html

I have tried casting it back to JSON, a Collection and a Map and nothing is letting me get the value from Body->Data->email.

I have tried getJSON(), get() and getKey() and can not get anything other than the top array cast to a variable.

body.getJSON("data") and responseBody.getJSON("data") both return null which makes no sense given debug 'info' shows it is properly formatted JSON.

Possible the issue is that Collection on Zoho needs to be either a simple list or a list of key/value pairs, and my body is a mix of both.


Solution

  • the reason for the error is the body sent in the webhook that you mentioned is INCORRECT format, look between the key of "ip_signup" and "merges", there is "NO COMMA". it should HAVE COMMA. enter image description here