API GET request for dynamic data

Hi there,
I am trying to get data from another application to bubble app through API request in which I want to enter dynamic token number. While creating params for that in API, Bubble asks to enter at least one value for the key.

  1. I’m not able to save the API call if I enter any string, so I am supposed to enter any valid sample token number. I want to call API though I enter any string value.
  2. The entered valid token number binds with the path id when save it. As a result, I am not able to call API for the dynamic token number I enter in UI.

If anyone have knowledge on this, please share.

Thanks in advance.

Hi @dineshkumar.a :wave:

To insert dynamic content in you calls you should use “[variable_name]” if the variable is in the URL and “<variable_name>” if the variable is in the body.

Can you share some images of your setup?

Hi @rpetribu,

We used the mentioned brackets in the call.
Let me share the specific part where I’m stuck with images.

For the specific key, we’ve given a dummy valid value.
While we try to map data to be displayed in the UI, it shows like as it is hardcoded (being not able to get data for dynamic input).
While for other similar API call, we are able to get data for dynamic input.

If I give invalid dummy value or null value, API is not called and cannot map the external API data.

Attached the images of the API call and workflow pages. You can see when I try to map data, it shows only the value I entered in the API call as it is hardcoded.
As a result, I am able to get only the data of the particular id.

Can you guess where could be the problem? From the bubble side or from the other software side? Hope this explains the problem.

Thanks in advance!!



The input value is not hardcoded, as you can see from your last screenshot, you can dynamically input the (path) id, and the call is being set up correctly.
The dynamic expression in the second screenshot (the one showing all the 23839s) is just making available the response of the API.
The 23839s are actually in the key values of the API response. The API you are calling is prepending the ‘id’ associated to the call to all the key values.

This practice is a form of namespace isolation, and I personally hate it. The benefit is that supposedly it helps to avoid data conflicts (accidentally putting the data of one account in another account), disadvantage is that its a pain to deal with.

I fyou set the dataType of call to JSON, the Bubble API connector will not be able to handle namespacing, because it cannot handle dynamic key names. After initialisation, all subsequent calls will have different key values ie (23839 id → 24259 id) and the API connector will not retrieve them.

You will have to set the Data Type to ‘Text’ and manually parse the response on the clientside :partying_face: fun

Thanks for your kind response @nico.dicagno,

The actual problem is we are able to GET the data only associated with the id no: 23839 (which is given as sample in API config).
We are able to map the input text data to the API call, still the result we get is only from the id 23839, no matter what the input is given in the text box.

Whereas, for other API call, we are able to GET data associated with the id mentioned in the input text box (we get correct data for the dynamic input given).

The provider has mentioned Get Team Abstracts Endpoint. Above screenshot is the API call which we managed to get data based on the dynamic input.

But for the one in which I am facing issue, the provider has mentioned only Get.
image

Might this be a reason for the issue - not getting the data based on the given input in the input text box? Or am I missing something in Bubble?

Already happened to me.

Two things you can do:

  1. Erase the dummy data provided as the URL parameter during the configuration of you call. Leave it empty. You will see that it is not necessary to reinitialize it.

If doesn’t work…

  1. Erase the call. Build it again.

Worked for me.

Can you share the initialisation popup of the API call that isnt working properly?

@nico.dicagno

Please look into the initialization popup of the API call.

Hope it helps.

@rpetribu

Thanks for your response.

We tried the same, but it is not working. Facing the same issue again.

Can you also share a screenshot of the Initialisation call using another id please.

@nico.dicagno

This is the initialization call for another data field, but set up in the similar way.
I’m able to get data output for the input data I provide in the UI for this call.

But, in the one which I face problem, it shows as the dummy id is bound with the call. So, it gives result for the same id, but not for any other id (even for valid id).

Thank you.
But I asked for the initialisation call of the same API, but with another client ID. Can you share one please

Oh Okay. Misunderstood that.
If I give another ID in the API call, it gives data corresponding only for that ID.
My need is it should get data for the ID that I enter in the UI.

Ok. I stand by what i said in the first post. The problem is that the API uses name space isolation.
Re-read my first post carefully :slight_smile:

I can try to give a better explanation:
The API is actually always returning the data of the ID requested in the UI. However the problem is that the API uses namespace isolation and the response keys will always have the requested ID at the front, which is different every time. The response keys are dynamic .

The API connector json parser cannot handle dynamic response keys.

When initialising the API call, the API connnector will set the key names to the the ones returned during initialisation, which will have prepended the ID you used to initialise.
In all future API calls, the parser will always try to find the values attached to those specific key names. But it wont find those keys, because the key names will be different, because you are using a different ID.

Solution:
Sadly you cannot use the API connector’s json parsing. If you want to get this to work, you have to set the ‘return type’ of the API to ‘text’ instead of json. This will make the response of the API just a block of text. You’ll then have to parse this yourself using :extract with regex or even using a JSON parser plugin.