Processing webhook payloads which are Array's doesn't work - here's a FIX

I noticed today that when receiving a webhook from Sendgrid for Mail Activity, the payload is a JSON Array, not a JSON Object. This get’s received by SimpleQ fine, BUT, when the message is processed, the actual payload element sent to the subscriber is just an empty JSON Object. I tracked it down to the params being sent to the ‘deliver staticDSN message’ script.

To fix this, adjust the $params variable being send in both the ‘flush queue’ and ‘ban Retry’ scripts to this:

Let ( 

[

payload = MESSAGEQUEUE::message
; payload_json_type = JSONGetElementType ( payload ; "" )
; channel = MESSAGEQUEUE::channel

; message_object = JSONSetElement ( "{}" 
		; [ "payload" ; payload ; payload_json_type ]
		; [ "channel" ; channel ; JSONString ]
		)




]
;


JSONSetElement ( "{}" ; 

 	[ "message" ; message_object ; JSONObject];
	[ "listener.listener" ; SUBSCRIBER::listener ; JSONObject];
	[ "listener.type" ; "staticDSN" ; JSONString ]

)


//Close Let
)

Hope this helps!

Note this requires FM version 19.5.1 or later:
https://help.claris.com/en/pro-help/content/jsongetelementtype.html?cshid=HID_Calc_JsonGetElementType

Thanks James :slight_smile:

Todd