How do I set a custom state with the results of an API call?

I’m trying to set a custom state directly from an API call. e.g. I have an input from the user that I’m submitting to an API and the API is responding with JSON. I’d like to set a custom state with one piece of data from that json. When I get the results of that step in the backend workflow, however, I don’t see an option to get at the nested data.

Do I need to save the data to the database before I can access it via custom state?

1 Like

Scheduling a backend workflow returns a text that is the id of the scheduled workflow (to use in case you want to cancel it).
The data from an api request is available only inside the workflow where you are making the request.
If you need to use it outside the workflow you need to save it in the database.

I hope this helps.

Cheers
Mariano

That does help! I was also wondering why it was returning a number!

Thank you!

Happy to help :slight_smile:

Cheers
Mariano

Hi, I’ve ran into a similar problem. Looked at a lot of forum messages to find out. But this time the API request is actually done in the same workflow, see this image:

For reason of speed I want to save the result list from the API, right to the custom state.
Do I need to map it before running the set state? Cause I can’t wrap my head around the provided options.

To clarify, the list each contains key-value pairs, like this:
[{"GUID":"fc4e49b0-92f0-4182-acdb-c005b73db970","Name":"Kiwi","Quantity":1},{"GUID":"05729b48-ac97-4326-8175-d268d604dbbc","Name":"Pineapple","Quantity":2}]

And the used data type in Bubble has the same fields:
image

if you want to store the result of a request in a state the data type of the stateneeds to be the same of the request.
If you want to map a list of key/values to a list of things in the db you need to create a backend workflow where you map and save a single thing, then schedule the workflow on the list of returned values. It’s something async and it will not be ready in the db on the next steps of the workflow.