Expand my Community achievements bar.

SOLVED

Fusion Webhook response

Avatar

Level 3

Hello,

 

Sorry that this question is very basic, but I've been in and out of so many coding languages lately that I need to ask.
Can I webhook repsonse return an array?
I have a test scenario where I'm creating an array but when I send that array in a webhook response, it looks like it gets flattened into a data string separated by commas.
Makes me think a webhook response doesn't respect data types?

 

thanks,

Kelly

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hello, yes you can.
Your JSON should look like this:

{
    "array": [
        {
            "ID": "t",
            "name": "User t",
            "objCode": "GROUP",
            "owners": [
                {
                    "ID": "tt",
                    "name": "User",
                    "objCode": "USER"
                }
            ]
        },
        {
            "ID": "tes",
            "name": "Group",
            "objCode": "GROUP",
            "owners": [
                {
                    "ID": "tested",
                    "name": "User",
                    "objCode": "USER"
                }
            ]
        }
    ]
}

Then, in the webhook, you will see it as a single item with an array inside.

AndrewShevchyk_0-1760117875746.png

However, if you send the JSON in this format:

[    
   {
        "ID": "t",
        "name": "User t",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tt",
                "name": "User",
                "objCode": "USER"
            }
        ]
    },
    {
        "ID": "tes",
        "name": "Group",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tested",
                "name": "User",
                "objCode": "USER"
            }
        ]
    }
]

Then it will create a bundle for each item, instead of one item containing the array.

View solution in original post

2 Replies

Avatar

Level 6

Hi @Kelly_StarzEnt,

 

When you say it gets flattened to data string what does this mean?

I have tested this and the response basically creates JSON representation of the array something like, for example here you can see response for array of user groups, and then the json array can be processed later on (also can be converted back to array by using "Parse JSON" module)

 

[    
   {
        "ID": "t",
        "name": "User t",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tt",
                "name": "User",
                "objCode": "USER"
            }
        ]
    },
    {
        "ID": "tes",
        "name": "Group",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tested",
                "name": "User",
                "objCode": "USER"
            }
        ]
    }
]

 

Hopefully this helps, please let me know if you have any other questions.

 

Best regards,
Ivan

Avatar

Correct answer by
Level 2

Hello, yes you can.
Your JSON should look like this:

{
    "array": [
        {
            "ID": "t",
            "name": "User t",
            "objCode": "GROUP",
            "owners": [
                {
                    "ID": "tt",
                    "name": "User",
                    "objCode": "USER"
                }
            ]
        },
        {
            "ID": "tes",
            "name": "Group",
            "objCode": "GROUP",
            "owners": [
                {
                    "ID": "tested",
                    "name": "User",
                    "objCode": "USER"
                }
            ]
        }
    ]
}

Then, in the webhook, you will see it as a single item with an array inside.

AndrewShevchyk_0-1760117875746.png

However, if you send the JSON in this format:

[    
   {
        "ID": "t",
        "name": "User t",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tt",
                "name": "User",
                "objCode": "USER"
            }
        ]
    },
    {
        "ID": "tes",
        "name": "Group",
        "objCode": "GROUP",
        "owners": [
            {
                "ID": "tested",
                "name": "User",
                "objCode": "USER"
            }
        ]
    }
]

Then it will create a bundle for each item, instead of one item containing the array.