Hey folks,
I’m trying to save a list of JSON objects (exercises), that are nested in another list of JSON objects (workouts), into the database. But I’m stuck!
Here is the JSON response I’ve got back. I’m trying to get this structure saved to the database. So a workout program, can contain a number of different individual workouts, and for each workout there are a number of individual exercises.
My database is structured:
Workout program >> contains list of Workouts
Workout >> contains List of exercises
I’ve tried to run an API on a list of ‘workouts’ (add_workout_from_list). which creates a new workout in the database and then runs another API on a list of exercises (add_exercises_to_wo) but I can’t seem to pass through the list of ‘exercises’ for each ‘workout’
Here are the parameters that ‘ad_workout_from_list’ API is asking for. I’ve tried exercises type as list of ‘text’ and ‘exercise’.
Any ideas on the best way to do this or where I’m going wrong?
1 Like
Create a backend workflow on a list and use the Exersizes list and Create a new thing.
2 Likes
Thanks Doug. I can save the workout list data and the exercise list data separately, but I can’t get them saved on the DB in the same way they are nested in the JSON.
For example, I can run a BE WF on Workout list fine, but then when I go to run a second BE WF on the Exercise JSON nested within one of the Workouts on the list, I can only get it to pickup the first exercise.
Any luck here? Facing the same exact situation.
Hey @akalati . I was using Open AI API to create my JSON so I changed the prompt so that the nested JSON output contained an identifier for the object it was nested in.
For example:
{ “Workout_Number”: 1,
“Workout_Name”: “Upper Body”,
“Exercises”: [
{“Name”: “Barbell Bench Press”,“Workout_Number”: 1 },
{“Name”: “Seated Rows”, “Workout_Number”: 1}]}
In this case the ‘exercise’ object contains the workout number of the ‘workout’ it is nested in.
I then ran seperate recursive backend workflows on list of workouts and list of exercises (with a 1 second delay for the latter). On the recursive workflow for list of exercise, after creating an exercise, I then made changes to a thing: 'do search for workouts where workout number = workout number in the exercise JSON. Therefore, linking the exercise to the workout it was nested in.
Yes, that’s exactly what I needed as well and would have solved so much headache. Do you suppose that can have OpenAI convince Amazon to do the same with their API responses
? I actually got it working, by scratching my left ear, with my right hand! I kept things on a flat level with the parent fields as-is, and each of the line’s fields as a concatenated blob that I then decompose into a native list. All this headache would be gone if bubble gave us a way to pass more than just primitives to BWFs!
I’m trying to understand that as well… Any chance you can share your database type ? Have you got all Workout and Exercice in the same Data table ? Or it remains in different tables ?
Thank you ![:pray: :pray:](http://forum.bubble.io/images/emoji/twitter/pray.png?v=12)