How to use dynamic content for body in API call to create multiple things with bulk create?

Hello,

I’m currently trying to create my first project with bubble.
I’m trying to acchieve copying a songlist by the Spotify API to my Bubble Database. I need this to let other users access the playlist items of one user and let them vote for the best song, to create something like a jukebox.
I tried multiple ways, e.g. with Scheduled API Workflows on a List. Which works but takes ages.
Now I’m trying to do it with bulk adding things via API. I used the API Connector plugin and created the post call to “https://[appname].bubbleapps.io/version-test/api/1.1/obj/[table]/bulk”.
Now I try to add multiple items at once, which is possible when I type in a manual body like this:
{“name”: “name 001!”}
{“name”: “name 002!”}

But I need dynamic values with unclear row count for this body. The body must be created based on the results of the API call to Spotify: “https://api.spotify.com/v1/playlists/[playlist_id]/tracks”. With x entries.

What I tried now is to create my own plugin which gets the result of the Spotify call as a list and returns a simple string that I can use as the body value within a the workflow API call to Bubble.

Then I use this string value of the plugin in my workflow:

When I now return from my created plugin a string: {“name”: “name 001!”} it works just fine.
When I try to return a string with linebreaks it doesn’t work anymore:
return ‘{“name”: “name 001!”}\n{“name”: “name 002!”}’


When you check it in debugger everything looks fine as it should work but it doesn’t create anything in the corresponding table. And I had a working version yesterday but then I started to create the whole thing with real values and somehow it doesn’t work anymore and I tried so many things to get it working again with this simple return value without success.

Now I hope anyone has an idea. Is this a bug or do I miss something. As said, it worked yesterday after many many tries but then it stopped working again and I can’t find anything else I can try.

Hope for some good feedback, thanks in advance.

There is no free lunch. Bulk create is no faster really than iterating over a list of primitives and creating Bubble Things out of them in the page or in a backend workflow.

However, as you’ve discovered, an API call can return to us an array. And you can just store that returned array. (Note: a Bubble list is not exactly the same thing as a JavaScript array, but it’s similar.)

And you can manipulate such arrays with List Shifter.

@tobihaas Did you find a solution here? I’m having the same issue where I’m sending the correct formatted text for the body but nothing is created in the db. But when i use that same formatted text directly in the body in the api connector, they are created.

I know this is a dead thread but, I had this issue too realizing the Body type has to be Raw

Then you do _*_body_*_ to dynamically fill in the body content

2 Likes