(POST API) Create a dynamique JSON code?

Hello,

I need to create a dynamic JSON code to make a POST API ;

In my program, I can create a team, from 2 to x people.

If the team is made up of 2 people, then the JSON code would have to adapt dynamically and send the information as an API POST.

If the team is made up of 8 people, then the JSON code adapts dynamically and the right information is sent by POST API.

I have the impression that the JSON code can’t be dynamic on Bubble, i.e. I have to pre-program several POST APIs and, depending on the number of people, the right JSON is chosen and the information is then sent to the POST API.

So I’m coming to you for your opinion and to find out if you’ve managed to do something dynamic if you’ve come across the subject? Because in my case, if I provide the JSON code for up to 10 people, maybe one day my client will need to include 15 and then it won’t work…

What do you think ? How to do it ?

Using JSON “text”, for example ;

Something like :

In the “API connector” plugin:

{
< dynamic-code-in-json-text-format >
}

And according to the choice of the number of members, bubble increments code in text format, which is then sent to “< dynamic-code-in-json-text-format >”

Is it possible to do this?

You will use :formatted as text on a list of team for example. This way, you can dynamically create an array in JSON

Thanks a lot

Can you please show me an example if possible ?

Not really, this depend of your JSON payload request. If you can share an example of the whole request, this could be possible to share an example.

1 Like

I understand, here is the JSON code ;

This is for 5 members, but i’m looking for creating ‘n’ members and the JSON code will be written dynamically

{
		"name": "<squad1-name>",
        "members": [
            {
                "assistantId": <id-Assistant1-squad>,
                "assistantDestinations": [
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant2-squad>",
                        "message": "<message-oral-ass1-vers-ass2>",
                        "description": "<condition-transfert-ass1-vers-ass2>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant3-squad>",
                        "message": "<message-oral-ass1-vers-ass3>",
                        "description": "<condition-transfert-ass1-vers-ass3>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant4-squad>",
                        "message": "<message-oral-ass1-vers-ass4>",
                        "description": "<condition-transfert-ass1-vers-ass4>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant5-squad>",
                        "message": "<message-oral-ass1-vers-ass5>",
                        "description": "<condition-transfert-ass1-vers-ass5>"
                    }
                ]
            },
            {
                "assistantId": <id-Assistant2-squad>,
                "assistantDestinations": [
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant1-squad>",
                        "message": "<message-oral-ass2-vers-ass1>",
                        "description": "<condition-transfert-ass2-vers-ass1>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant3-squad>",
                        "message": "<message-oral-ass2-vers-ass3>",
                        "description": "<condition-transfert-ass2-vers-ass3>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant4-squad>",
                        "message": "<message-oral-ass2-vers-ass4>",
                        "description": "<condition-transfert-ass2-vers-ass4>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant5-squad>",
                        "message": "<message-oral-ass2-vers-ass5>",
                        "description": "<condition-transfert-ass2-vers-ass5>"
                    }
                ]
            },
            {
                "assistantId": <id-Assistant3-squad>,
                "assistantDestinations": [
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant1-squad>",
                        "message": "<message-oral-ass3-vers-ass1>",
                        "description": "<condition-transfert-ass3-vers-ass1>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant2-squad>",
                        "message": "<message-oral-ass3-vers-ass2>",
                        "description": "<condition-transfert-ass3-vers-ass2>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant4-squad>",
                        "message": "<message-oral-ass3-vers-ass4>",
                        "description": "<condition-transfert-ass3-vers-ass4>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant5-squad>",
                        "message": "<message-oral-ass3-vers-ass5>",
                        "description": "<condition-transfert-ass3-vers-ass5>"
                    }
                ]
            },
            {
                "assistantId": <id-Assistant4-squad>,
                "assistantDestinations": [
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant1-squad>",
                        "message": "<message-oral-ass4-vers-ass1>",
                        "description": "<condition-transfert-ass4-vers-ass1>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant2-squad>",
                        "message": "<message-oral-ass4-vers-ass2>",
                        "description": "<condition-transfert-ass4-vers-ass2>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant3-squad>",
                        "message": "<message-oral-ass4-vers-ass3>",
                        "description": "<condition-transfert-ass4-vers-ass3>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant5-squad>",
                        "message": "<message-oral-ass4-vers-ass5>",
                        "description": "<condition-transfert-ass4-vers-ass5>"
                    }
                ]
            },
            {
                "assistantId": <id-Assistant5-squad>,
                "assistantDestinations": [
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant1-squad>",
                        "message": "<message-oral-ass5-vers-ass1>",
                        "description": "<condition-transfert-ass5-vers-ass1>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant2-squad>",
                        "message": "<message-oral-ass5-vers-ass2>",
                        "description": "<condition-transfert-ass5-vers-ass2>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant3-squad>",
                        "message": "<message-oral-ass5-vers-ass3>",
                        "description": "<condition-transfert-ass5-vers-ass3>"
                    },
                    {
                        "type": "assistant",
                        "assistantName": "<name-Assistant4-squad>",
                        "message": "<message-oral-ass5-vers-ass4>",
                        "description": "<condition-transfert-ass5-vers-ass4>"
                    }
                ]
            }
        ]
    }

In API Connector

{
		"name": "<squad1-name>",
        "members": [<members>]        ]
    }

In your “members” field, Do a search for members:formatted as text
First box, probably something like

{
                "assistantId": This member assistand ID (dynamic),
                "assistantDestinations": [Do a search for destination:formatted as text with a constraint for current member]
            }

And comma for second box (delimiter)
In the second formatted as text for destination

                    {
                        "type": "assistant",
                        "assistantName": "This assistant name (dynamic)",
                        "message": "This assistant message (dynamic)",
                        "description": "This description (dynamic"
                    }

Delimiter comma.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.