Hi folks,
I have a process for turning data obtained through the API connector into Bubble objects (using a recursive backend workflow). It works great when the JSON data has a consistent format, but I’ve run into an issue when things aren’t uniform.
The data is coming from Spotify, and a simplified view of the JSON looks like the example below. As you can see each “Track” has one “Name” but can have one or more “Artists” (when there are collaborators on a song).
{
“Tracks”: {
“Items”: [
{
“Track”: {
“Name”: “Track Name”,
“Artists”: [
{“Name”: “Artist A”},
{“Name”: “Artist B”}
]
}
},
{
“Track”: {
“Name”: “Track Name”,
“Artists”: [
{
“Name”: “Artist C”
}
]
}
},
{
“Track”: {
“Name”: “Track Name”,
“Artists”: [
{
“Name”: “Artist D”
},
{
“Name”: “Artist E”
},
{
“Name”: “Artist F”
}
]
}
},
{
“Track”: {
“Name”: “Track Name”,
“Artists”: [
{
“Name”: “Artist G”
}
]}}]}}
What I want to extract from this JSON is only the first artist name for each track, so a correct outcome would be an artist list like this:
Artists [“Artist A”, “Artist C”, “Artist D”, “Artist G”]
But what I get is the whole list:
Artists [“Artist A”, “Artist B”, “Artist C”, “Artist D”, “Artist E”, “Artist F”, “Artist G”]
The way I’m doing it in Bubble is like the screenshot below. Basically, I call the backend workflow passing in a list of artists, a lists of track names, an index and the track count. Then on the backend it cycles through the data creating Bubble objects until it reaches the end of the list.
The problem is when there are more than one artist, as it’s pulling all of them which means the Bubble objects get created with artists that are out of sync with the track names.
You can see in the Artists field it’s taking the result of the Spotify API call, and getting:
Each item’s track artist’s name.
What I really need is a way for the list to only have the first item from each artist, but I haven’t been able to figure it out.
If I try putting :first item in there to create:
Each item’s track artist:first item’s name
It just takes the first item and is no longer a list. I need a way to insert the :first item inside the expression vs. at the end, but that’s not possible in the expression builder.
For example, in the screenshot below, I can get the list of artists for the track, and I’d want to then choose :first item, but have it be the :first item for every artist. As soon as I introduce :first item it ends the ability of it to be a list.
The last screenshot shows what happens if I insert :first item (leaving only the name as an option vs each item’s name).
I’ve tried to use a filter and a ton of other approaches but can’t for the life of me get it to work.
I can’t make the app public (wish I could make the editor view public for just one page).
Doesn’t anyone have an idea how I can use the expression builder to pull this first item of each?
Thanks in advance,
Oli.