Backend workflow JSON array actions for each line

Hello Bubblers!

I’m working on a backend workflow in Bubble and I’m facing a challenge I hope you someone help me with.

I have a JSON response (array). The structure of the JSON is as follows:

[
	{
		"unique": "2688\t200\tOnbekend",
		"amount": 2,
		"unit_id": 0,
		"unit_txt": "vel",
		"code": "07-0000-0335",
		"description": "MC glanzend 320 x 460 mm 150 g/m²",
		"supplier": "I",
		"source": "Onbekend",
		"ordered": false,
		"reference": "D5307114\t",
		"usedby": "D",
		"claim": "FSC Mix Credit"
	},
	{
		"unique": "2606\t200\tOnbekend",
		"amount": 57,
		"unit_id": 0,
		"unit_txt": "vel",
		"code": "07-0000-0157",
		"description": "MC glanzend 320 x 460 mm 300 g/m²",
		"supplier": "I",
		"source": "Onbekend",
		"ordered": false,
		"reference": "D5307115\t",
		"usedby": "D",
		"claim": "FSC Mix Credit"
	}
]

In this JSON, I want to use the “unique” and “amount” in the next action. The action is again a API call for line 1 of the array, and line 2 of the array.

However, the number of line items can vary from 1 to 6 or more.

My current approach involves creating multiple actions with a control check like “IF count is 2, then execute index 2”. However, I’m seeking a more elegant and efficient solution.

What would be the best practice in this scenario to dynamically adjust the number of actions based on the JSON array? Any tips or examples of similar workflows would be greatly appreciated!

Thank you in advance for your insights!

Martijn

Schedule API workflow on list of JSON objects and use parameters (This Object’s unique / This Object’s amount)

Okeay, thanks but how. I create 2 backend workflows I asume. The first one to get the list (JSON above) and then another backend workflow where I make the API call’s that I want to run on that list.

But how to start? List to run on (result of step 1) is red?

When you schedule the backend workflow on a list, the backend workflow will run for each list item. So, if you want to create a thing and make changes to something else for each item in the list, you’d have Create a new thing and Make changes to a thing in your backend workflow.

List to run depends on your step 1 response, just try out lots of stuff and you’ll find the right thing eventually… It’s the list of objects returned from your API call.

Thanks but after setting up the API call, it looks it is not seeing it as a list …

JSON looks like this:

[
    {
        "unique": "2624\t200\tOnbekend",
        "amount": 76,
        "unit_id": 0,
        "unit_txt": "vel",
        "code": "01-0201-0073",
        "description": "HVO Offset 320 x 460 mm 400 g/m² 0,44 mm",
        "supplier": "Igepa Nederland BV",
        "source": "Onbekend",
        "ordered": false,
        "reference": "D5306950\tD5306952\t",
        "usedby": "D",
        "claim": "FSC Mix Credit"
    },
    {
        "unique": "3003\t200\tOnbekend",
        "amount": 304,
        "unit_id": 0,
        "unit_txt": "vel",
        "code": "01-0201-0071",
        "description": "HVO Offset 320 x 460 mm 300 g/m² 0,34 mm",
        "supplier": "Igepa Nederland BV",
        "source": "Onbekend",
        "ordered": false,
        "reference": "D5306951\t",
        "usedby": "D",
        "claim": "FSC Mix Credit"
    },
    {
        "unique": "160\t0\tOnbekend",
        "amount": 32,
        "unit_id": 1,
        "unit_txt": "mtr",
        "code": "",
        "description": "Lamineren mat (320)",
        "supplier": "",
        "source": "Onbekend",
        "ordered": false,
        "reference": "P9447777\t",
        "usedby": "P",
        "claim": ""
    }
]

I think it’s because it’s expecting something like the following:

{
"items": [
    {
        "unique": "2624\t200\tOnbekend",
        "amount": 76,
        "unit_id": 0,
        "unit_txt": "vel",
        "code": "01-0201-0073",
        "description": "HVO Offset 320 x 460 mm 400 g/m² 0,44 mm",
        "supplier": "Igepa Nederland BV",
        "source": "Onbekend",
        "ordered": false,
        "reference": "D5306950\tD5306952\t",
        "usedby": "D",
        "claim": "FSC Mix Credit"
    }
]
}

My solution will only work if Bubble recognises each object as part of a list which obviously it isn’t doing right now. There are some workarounds e.g calling a custom API endpoint with the API response that adds the necessary formatting to the original JSON so Bubble can use it but it’s a bit janky…

Fixed it. In the API call I selected “Capture response headers” it then initialize the body as a list and then the schedule API workflow is working. Thanks @georgecollier for the help and insights!