Question

Accessing nested JSON array in Zap Webhook

  • 29 September 2021
  • 3 replies
  • 316 views

Hello,I'm trying to get some fields from a JSON webhook to send to active campaign, but I'm not succeeding. I create a ZAP to run a JavaScript, but I'm not getting it, can you help me?

My json Data:
 

{

  "type": "sale",

  "event": "saleUpdated",

  "sale": {

    "code_url": "https://www.xxx.xxx.xxx",

    "barcode": "123 1234 1234",

    "expiration_date": "2021-10-02T03:00:00.000000Z"

   "amount": 397, "proposal_id": null, "paid_at": null, "updated_at": "2021-09-29T17:27:53.000000Z",      "created_at": "2021-09-29T17:27:52.000000Z", "id": 16395,

  },

  "client": {

    "name": “myname”,

    "email": "test@gmail.com",

    "cellphone": "+5519987654321",

    "cpf_cnpj": “123.456.789-06",

"status" : "approved",

"age": "xxx"

  }

}

 

I need get name, email, cellphone, cpf_cnpj fields on client key, and code_url, barcode, expiration-date, amount on sale key. Can you help me?

 

My ZAP Flow:

 

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +14

Hi @Kinoquix 

There are errors with the JSON structure.

Check your JSON here: https://jsonlint.com/

 

Once you clean up the input Data, then you can use this JavaScript code:

 

Snippet from Code output

 

Hi @Troy Tessalone 

I tried this and I still get another error, I need to get the client and seller key data, and I still can't.

I don't know where I'm going wrong. I'm a beginner in programming.

This is my full payload:
 

{
    "type": "sale",
    "event": "saleUpdated",
    "sale": {
        "code_url": "https://www.xxx.xxx.xxx",
        "barcode": "123 1234 1234",
        "expiration_date": "2021-10-02T03:00:00.000000Z",
        "amount": 397,
        "proposal_id": null,
        "paid_at": null,
        "updated_at": "2021-09-29T17:27:53.000000Z",
        "created_at": "2021-09-29T17:27:52.000000Z",
        "id": 16395
    },

    "client": {
        "id": 7855,
        "name": "myname",
        "email": "test@gmail.com",
        "cellphone": "+5519987654321",
        "cpf_cnpj": "123.456 .789 - 06",
        "status": "approved",
        "age": "xxx"
    },
    "product": {
        "id": 1141
    },
    "seller": {
        "id": 4412
    },
    "affiliate": null,
    "productMetas": [],
    "proposalMetas": []
}


zap error:

My zap task:

 

This post has been edited by a moderator to remove personal information. Please remember that this is a public forum and to remove any sensitive information prior to posting.


Thanks =)

Userlevel 7
Badge +14

@Kinoquix 

Might be with how your are testing.

The mapped “Sale” data point has “No data”.

Try testing with a different example that has the JSON populated.