Sending Array of objects via backend workflow help

I have a 3rd party API that will occasionally push some updates to my bubble app.

Basically to just create some entries in a products data type. The data type has 5-6 fields in the DB but the fields of note for this API POST are ‘sku’ and ‘name’.

My data structure that is being posted to the backend public workflow looks like this:

{'items': [{'sku': 'test', 'name': 'myfirstname'}, {'sku': 'test2', 'name': 'mysecondname'}]}

I think I have a good grasp on the concept of having a public backend workflow that accepts parameter ‘items’ then an action that schedules an api workflow on a list. That workflow then contains the ‘create a new thing’ action.

However the issue I am running into is with data types I think. On my public API workflow I have my parameter as ‘items’. If i set the datatype to ‘text’ I run into an issue where I cant seem to define the name & sku at the create a thing step.

However if I set the incoming data type (from the public workflow) to type: Products I get the following error when I POST my api call to bubble.io

{"statusCode":400,"body":{"status":"MISSING_DATA","message":"Invalid data for key items: object with this id does not exist: sku"}}

Again, if I set the datatype to ‘text’ the API call is successful but the data pushed into the database is incorrect. Any help appreciated. See imgur below:

Tested using type ‘text’

Tested using type ‘text’

So i guess my question is. What is the proper way to POST an array of objects, and have those objects each created as items in a database.

Instead of a manual definition, use “detect request data” so Bubble can receive a sample payload and learn the structure.

Once you change that setting, click on “detect data” and Bubble will show you a popup with an initialization endpoint. Note how the end of this endpoint has the word “initialize” in it. This isn’t the permanent endpoint, it’s just for this initialization.

Manually trigger a request to your API workflow (from the 3rd party app, Postman, etc. ) with the JSON array. Make sure this popup is open while you trigger in a different window.

After you trigger, the popup will change automatically to show you the incoming data all parsed out for you. Click Save.

Now, in your workflow to create, you’ll be able to reference the “request data’s” list and fields. Try it out!

Cheers,
Gaby
Coaching No Code Apps

1 Like

So I think that did at least help me identify the issue.

When running detect this is what the raw data looks like:

My actual payload though is:

{'items': [{'sku': 'test', 'name': 'firstname'}, {'sku': 'test2', 'name': 'lastname'}]}

Seems like it doesnt like request data as my schedule api to run on list

Try using double quotes around all your keys and values. It should be parsing out all the fields to give you more access to them in the workflows.

Getting the same results:


The raw data doesn’t show each item surrounded by curly brackets. The code you pasted looks right, but it’s different from what Bubble is receiving. Check on that?

1 Like

Is not a valid json. You need to convert it with doubles quotes.

{
    "items": [
        {
            "sku": "test",
            "name": "firstname"
        },
        {
            "sku": "test2",
            "name": "lastname"
        }
    ]
}

Also, you need to select, in type of thing: Request data items that is the correct type for your list (request data is an object and not a list)

I did that and what is being received by the data detection on the bubble API is this:

On your second point, not following. Here?

Thankyou!

Can you share how you send it? Postman settings? I’ve tested and didn’t get any issues…
Also, be sure to have content-type : application/json as header in your request

Got it working thanks for the help all.

For people in the future who see this, make sure your inbound API call is actually formatted as JSON. Added the proper header and used the py requests library properly and everything started working.

Thanks all.

1 Like