Skip to main content
Best answer

Items from Child Array Being Removed


I am working on a ZAP to get information about a thread in LiveChat.  I am calling a webhook and I get json similar to this:

 

{
    "id": "CHATID",
    "users": [],
    "thread": {
        "id": "XXXXXXX",
        "tags": [
            "CREATE FRESHDESK TICKET"
        ],
        "events": [
            {
                "id": "1",
                "type": "message",
                "text": "Thanks for stopping by, how can we help? ",
            },
            {
                "id": "2",
                "type": "message",
                "text": "hi",
            },
            {
                "id": "3",
                "type": "file",
                "name": "test.png",
                "url": "",
                "content_type": "image/png",
                "width": 100,
                "height": 100,
                "size": 12010
            },
            {
                "id": "4",
                "type": "message",
                "text": "here is a file to test getting attachments",
            },
            {
                "id": "5",
                "type": "system_message",
                "text": "archived the chat",
                "system_message_type": "manual_archived_customer",
            }
        ]
    }
}

What I want to do now is look to see if there are any file attachments.  The problem is that when I pass it to a Code step, it returns the items as a strings for the child objects.  So, each child object property is grouped by properties, so I get events type, events text, etc..  The issue is that if the first element is blank it removes them.  So, while file is element two (zero based indexes) when I look at events type, the corresponding events name element doesn’t exist, because it is element 0.  It is a bit frustrating as when you see fields that are being passed to the Code step, it shows “,,test.png,” for events name, but when I split the string, it just has one element.  How are others handling this?  I really just want to grab the events with a type of file and then process them.  Thanks.

 

Wade

Best answer by Troy TessaloneBest answer by Troy Tessalone

Hi @William Wade 

Good question.

Try using this Zap action: Formatter > Utilities > Line Items to Text

You can convert the array items to be a string that you can then parse in a Code step.

Guidance can be found in this related topic:

 

View original
Did this topic help you find an answer to your question?

2 replies

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30995 replies
  • Answer
  • October 6, 2023

Hi @William Wade 

Good question.

Try using this Zap action: Formatter > Utilities > Line Items to Text

You can convert the array items to be a string that you can then parse in a Code step.

Guidance can be found in this related topic:

 


  • Author
  • Beginner
  • 1 reply
  • October 7, 2023

That seemed to have work.  Thanks.