I have lists of text concerning files coming from an external API.
Each file has a file_title and a file_id. E.g. File 1 = [“Title 1”, “ID 1”], File 2 = [“Title 2”, “ID 2”]
I am trying to set it up so that users can select which file_title they want on the front end and set up a dynamic workflow in the backend for file_id.
E.g. if user selects “Title 2” in dropdown box then “ID 2” is dynamic value in workflow.
How am I able to do this?
I was unable to do it with custom states as there are two lists I want to save.
I tried creating a “file_entry” data type with “file_id” and “file_title” fields. But when I “create a thing” from the external api it only saves Title 1 and ID 1. Which makes sense because we’re only creating “a” thing.
But if I set “file_id” and “file_titles” to lists, and set the lists on the api, then I get 1 “file_entry” = [ “file_id” = (“id 1”, “id 2”) /// “file_title” = (“Title 1”, “Title 2”)]
I hope that’s clear. Your input would be greatly appreciated
I’m not familiar with API workflow or Bubble Data API - I tried just now to experiment with it but it said I needed to upgrade my plan for Bubble Data API. Would you know of another solution?
I often end up doing weird bits of manipulation on multiple lists like this, as bubble makes it necessary far more often than it should be.
My suggestion would be to create a single list, and for each entry format it as:
File_Title|File_ID
When rendering for users on the front end, call the list, split each entry by | and show the first item. For workflows in the backend, you split by | and select the last item or item #2 (doesn’t have to be | necessarily, I just use it because it’s uncommon).
This way you won’t need to save anything to the db at all, and can keep your API call as a data action only.
If you don’t want to save the files to your database, you can call your API with a data action and structure the response as below:
Response’s files:format as text(this file’s title|this file’s id)
If you want to create a database entry for each file, just select “add list” to the list field on your datatype, then apply the same logic (format as text on the list of files)
The challenge I am finding with doing this is picking the corresponding ID in the backend.
So if Title1|ID1|Title2|ID2 is saved in a custom state, the user is then shown a split version of Title 1 / Title 2 on the front end. But how would I be able to translate their corresponding ID choice?
By merging the lists previously I was able to achieve a similar front end, but the obstacle is the backend ID.
Since you’re keeping the title and id joined in each entry, when you need to use it in the backend you would just split by | and get the last item instead.