Handling JSON object from API call

I am receiving a JSON object from an API call and have trouble saving it in Bubble.
The initialization works, I am shown the expected JSON response (array containing 3 JSON objects with message, status, name keys).

And these are my data types:

The idea is to poll every few seconds for the JSON array and update a corresponding data type which is then used to show the 3 JSON objects inside the array via a repeating group.

I have trouble finding out what’s wrong with my setup, any help would me much appreciated.

The API call also fails in the Preview when using this workflow:

Error message:
Bildschirm­foto 2024-03-25 um 00.49.14

The server response is correct, I use it in a React app where it’s mapped over a list element. Having trouble translating this to Bubble obviously :slight_smile:

API Connector settings:

The erornis from.your request.probably not encoded correctly(bad JSON). Please share api connector settings

1 Like

Thanks, added them. Looked fine to me since the initialization seemed to work

In your API connector, you didn’t bset any double quotes around string value. So I guess you did it when you initialized it directly in value field. But in your action, you didn’t use :encoded as json-safe (this will encode the string and add double quotes around it). So you shoud probably set this in your action. However, if you have integer or boolean, you shouldn’t use :encoded as json-safe on them. Finally, if there’s any chance that you have an empty field, you may need to use terniary operator and set null if empty.

1 Like

right! missed the quotes. thanks
however, I cant find a matching type (JSON) for the array of json objects I receive. e.g. to display them in a repeating group

Actually, you have set your call as “action”. You need to set it as “Data” to use it in RG. In RG, you will be able to set the data source for this type and use Get Data from API To call your endpoint.

I need to set the call to “action” to update the data every few seconds

Why do you need to do that? Don’t API have webhook? Also, you can refresh data for a rg with action too.

the api endpoint has to be polled every few seconds for status updates from which some have to be saved for later use/download. that’s why I need it to be an action. works fine now, I just manually assigned each entry in the json array its own data field. :sweat_smile: