Saving data from an API call

Hi all,

I am new to Bubble and trying to teach myself, but have run into a block and would appreciate any help! I have already watched tutorials and read through a lot of documentation but am still stuck on what is likely a simple issue.

Here is what I have:

A request goes out from the API Connector to ChatGPT and it returns a Course Design Document (example below). The Course Design Document is displayed in a window with Auto-binding so the user can make edits. So far so good up to here.

Each Course Design Document ends with a Course Outline that gives information about each module of the course. I want to extract each module’s information from the Course Design Document and save it to Bubble so I can use it in the next API calls.

I found that I can ask ChatGPT to extract each module as a text string and return it as JSON or CSV but I am not sure how to save these returned variables in Bubble so I can call them later.

How can I save the data from API Connector to a specific data type and then call on that data field in another API call?

Thanks all!


Example Course Design Document:

Course Title: Anthropology of Religion

Course Summary:
This course explores cross-cultural varieties of beliefs in the supernatural and religious rituals people employ to uncover and shape their worlds. The course creates an understanding of diverse world religions through a cultural and historical lens. It will equip students with the knowledge and wisdom needed to critically analyze and appreciate varying cultural roots of religions across the globe, hopefully reducing bias towards various faith systems.

Recommended Textbook:
“Religions in Practice: An Approach to the Anthropology of Religion” by John Bowen (6th Edition). This textbook provides in-depth coverage of cross-cultural belief systems and rituals, aligning closely with the course summary, receiving positive reviews for its comprehensive portrayal of the topic, and is cost-effective for community college students.

Course Outline:
These are the sections of content I want to save as individual variables. Each module saved as its own field.

Module 1: Overview and Introduction
Learning Topics: Introduction to Anthropology of Religion, Understanding Bias, Ethnographic Fieldwork
Learning Outcomes:

  1. Students will be able to describe the anthropological approach to religion (Remembering)
  2. Students will evaluate personal biases towards different religions (Evaluation)
    Assignment: Students will write a short essay on identifying and understanding personal biases toward religions.

Module 2: The Nature of Supernatural Beliefs

Learning Topics: Cross-cultural supernatural beliefs, the Evolution of Supernatural Beliefs

Learning Outcomes:

  1. Students will be able to comprehend different cross-cultural supernatural beliefs (Understanding)

  2. Students will analyze how these beliefs have evolved over time (Analysis)

Assignment: Students will prepare a creative poster focusing on a selected supernatural belief’s evolution.

Module 3: Myth and Origin Stories

Learning Topics: Role of Myth in Religion, Selected Cultural Origin Stories.

Learning Outcomes:

  1. Students will compare different cultural origin stories (Analysis).

  2. Students will be able to represent an origin story visually (Synthesizing).

Assignment: Students will deliver a brief presentation explaining ordering selected principles from different cultural origin stories/themes in one visual arrangement.

Module 4: Rituals and symbolism

Learning Topics: Functions of Rituals, Symbols in Religious Practices.

Learning Outcomes:

  1. Students will create a comprehensive chart of different religious symbols and their meanings (Creating).

  2. Students will appraise the cultural impact of selected religious rituals (Evaluating).

Assignment: Students will complete research on selected ritual, and present findings in a 5-page paper.

Dr. Sam,

Change the “use as” type of the API call to “action” and then call it from the workflow. You can then reference the API response (to store or for use in subsequent API calls “within scope”) using "result of step [step of the API call] body".

1 Like

TLDR; The solution uses only API workflow in backend & schedule API workflow in front end to pass the text through that workflow & convert into arrays that are accessible & can be stored in db + you have to be very specific with GPT in order for it to work.

I just spent 3 days trying to figure out how to parse GPT json safe responses into the database by converting the into lists, this is ONLY for lists, you should be able to parse into text all on the front end.

SO;

  1. you need to create a backend workflow “API workflow”, check all the boxes & set to POST, manual parameters, key: “whatever you want”, value can be text/array/list

  2. create a trigger to that backend workflow in step 1 → in the FRONT END workflow, preferably in whatever workflow triggers the GPT call. Set the empty field that you named in step 1 as the content from GPT (now you parse it before it passes it to the backend workflow - I used GPT to generate regex to isolate what I wanted from the response, then FORMAT AS TEXT into a json array.

  3. now go back to the BACKEND, set up an action under the API workflow, and here you can access the items that you created in step 2 to save them to a database

NOTE, I spent the last 2 days using API Connector and could not figure it out. Using the original settings from a previous tutorial I figured out that GPT responds in javascript and the response is JSON-safe. So I couldn’t parse the response that way, or couldn’t figure it out.

Thank you. I do use this “result of step 1” in the workflow for the page. How would I call the “result of step 1 body” in a different workflow? Does it have a variable name that I can call later?

Unfort it doesn’t (no scope variables). However you can pass the body as a parameter to the other workflow.