Webhook JSON parse array

Anonymous
Not applicable

Webhook JSON parse array

Hi All,

I am trying to parse a JSON response in order to implement error handling.

My response is
[{"message":"insufficient access rights on cross-reference id: 00QN00000012BjY","errorCode":"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","fields":[]}]

Note that an unreferenced array is returned ( [.....] ).  If the response was {"errorCode":"errormsg"} then this would parse easily.  However, I dont have control over the system returning the message so I need to parse an array.

How do I reference the errorCode?

I have tried:
[0].errorCode
errorCode[0]
[].errorCode

But nothing I try works.  Has anyone come across this?

Thanks!


 
Tags (1)
4 REPLIES 4
Anonymous
Not applicable

Re: Webhook JSON parse array

I think you need to add a dot to your second one to make it work. Try:
.errorCode[0]
Chad_Caldwell
Level 1

Re: Webhook JSON parse array

Did you ever figure this out? Hitting same issue.

I would assume it's something like: response[0].errorCode (where "response" is the name of the returned object). This does not work just saying what I think it should be.

Thanks.

SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook JSON parse array

Response mappings start with a dot-property of the response object. If the outermost response object is an array, you can't dereference it this way.

If you're forced to use an endpoint like this I would gateway it through something like AWS APIGW and wrap it in another object.

Responses like this aren't typically made for webhook environments.

Maarten_Westdo2
Level 2

Re: Webhook JSON parse array

Hi Chad,

I was running into the same issue. However I had 2 differences but perhaps this helps you in the right direction.

Firstly I only cared about the first response in the array so that makes it easier but if you are expecting multiple ones you would just need more fields to store the information in.

For the mapping. I didn't have an array name - I know weird but as you I had to work with what I received.

Here is the array response message:

pastedImage_0.png

The [ ]  means it is an array otherwise these wouldn't be there.

I was able to map the sender field using it using:

pastedImage_2.png