Save data response from API with field mapping

Hi everyone,

I’m trying to implement a functionality in my app, where a user transfers data from external sources (via API) to the Bubble database. The data coming from the API is an array of objects, so this array has to be saved as a list of Things of the same Data type.

The fields coming from API could be very different from those already existing inside the needed Data type in my DB. So the user needs to have the possibility to map them together at his choice. And this is the part I’m stuck on.

I’m aiming to implement something like the CSV uploader does, giving you the option to map fields prior to actually creating Things in the DB:
image

What I’ve got:

  1. I’m able to get the list of fields from the API I’m working with using a separate API call, which I can use then for mapping.
  2. Also with a plugin I got the list of Bubble fields of needed Data type.

Now a few questions:

  1. How do I approach the mapping functionality in general? Do I first save in some form mapped fields e.g. key-value pairs, and then use it when I do the actual API request to GET my array of objects? (sounds like using tons of conditions as I have around 100 fields)

  2. And after that, how do I actually save that data to Bubble? Scheduling a workflow on a list of objects from my array or, maybe, using Data API endpoint to bulk-create Things?

I’ve searched for the solution on the forum, but couldn’t find anything similar. So I would really appreciate any help. Let me know If I missed something or I need to elaborate on further. Thanks a lot!

Yep I would think of it like that, stage 1: store as JSON object. Stage 2: let the user manipulate this data, probably in a RG and probably with some kind of custom states which can be toggled to select the corresponding bubble field types. Stage 3: run a backend workflow to process this data.

Very cool and complicated process!

Hi Oliver,

Thanks for taking the time. Could you please elaborate on what you mean by save as JSON and manipulate it? Can’t imagine how I’d use the huge JSON here.

Perhaps I’m misunderstanding part of it, ATM are you just taking all the key value pairs and storing them in a datatype with key and value text fields?

I was thinking you meant either that, or using the whole json to populate a repeating group with the key value pairs for the user to them select which should be assigned as what field etc.

I would imagine the last phase you would just want a list of the fields you need them to have, with a dropdown of the data imported, so they can select each ones type, and then kick off the workflow based on those selections right?

Sorry @Oliver-wholegraintech for the late reply. I was trying things here and there and in the end, found it to be too complicated to do it using native Bubble features.

A little Python script hosted elsewhere built in 15min solved the issue. Thanks for spending some time here : )

1 Like