I’m been playing around with codeless APIs and I’m struggling to create an API that loads a table data based on a property from another table.
This API call would identify the age of the current user from the profile table and load the corresponding tables habits. For example, my users would be between 5-8, 9-12 and 13-16 in age and age is stored in the profile table in a generated column based on their date of birth. If the user is between the ages of 5-8, I would like to load the table (with all its objects and properties) habits_5_8, if the user is aged between 9-12, then I would load the table habits_9_12 and so on.
So far I’ve managed to build out the codeless API to identify the user age based on this youtube video but I can’t figure out the next step to load the corresponding table. I tried creating a new method in the same service to perform this next step but I don’t think that is the way to do it.
Here is a screenshot of the codeless API thus far. (Also the between operator doesn’t return any data but when I search for a specific age it does)
I’ve gone through most of the youtube videos on codeless APIs and even tried the Udemy course but that was all about the UI builder and using codeless logic in there.
I was using User_ID as I had mistakenly thought that I needed to search through the User_ID to identify the current user.
How do I get the block for Method Argument? All the videos have shown that this appears in the context blocks ribbon at the top of the designer but it isn’t appearing for me. See screenshot below.
Also in your setup, you have habits.name. Can I check that habits is the table and name is the property? In that case should I have all the habits in 1 table as I’ve broken them out across 3 tables presently as I’m unsure how to assign the objects to a particular age.
I’ll add that I’m new to development. I’m loving the Backendless system thus far and would love to really get to know how to use the Codeless system proficiently. I’ve found this help guide on the codeless system but is there currently a guide that outlines the use cases for each of the blocks?
When you create a method, then you can specify the method parameters. You can also edit the current method and specify them. Once this is done, the corresponding blocks will appear in the Codeless panel. https://monosnap.com/direct/Pq7MCaz5059NnfnnL8A9xMNDzKEq8v
However, I’m struggling to follow how the system will know which habits are related to which age group. e.g. water (habit 1) is for the age group 5-8, sleep (habits 2) is for the age groups 5-8 and 9-12 and exercise is for all the age groups, 5-8, 9-12 and 13-16. How does the database/API call know which habits to display depending on the user’s age?
Also, I’m getting a 400 error with the query schema ‘age>= and age<=’.
I’m still struggling to follow how this API call knows which habits belong to which age group. My understanding of this API call, it will return the habits which have been assigned to the user profile, as per the relation in the table schema.
To clarify, I’m building out the user’s onboarding (sign-up process) in my mobile app. The user has no habits assigned to their profile yet. This API call would identify the habits that are appropriate for the user’s age and pass this to the frontend to display them. The user will select the habits they choose to track for the given month and then I will presumably need another API to send the chosen habits into the database, assigning them to the user.
I’m confused as there are no data points in the table scheme against the habits to show which age group they would belong to.
I hope I’m making sense here, please let me know if I’m not.
By looking at your schema (in the screenshot above in this thread) I see that a profile object may have one or more habits. When you say “how this API call knows which habits belong to which age group” , I am trying to understand what you mean by that. If there is a relationship between a profile and the related habit objects, then the relation is right there: for a given profile, you get the related habit objects. This is the source of my confusion, I guess I do not understand what you’re trying to do. Could you clarify?
Thank you for the detailed explanation. Now I understand it better. Do you mind sharing your application ID so I can take a look at the data in addition to the schema?
Thanks. I see that the habits table has the agegroup column, but there are no values. Where would the information be that defines what habits correlate to each of the age groups? This would be critical in order to come up with the query that you need.
That was actually 1 of the areas I was struggling to see how I can structure the data but I just had a brain wave that if I add them all as different objects (even though most will be repeated) it can be achieved that way. It also gives me the flexibility to customise the language to the different age groups.
I’ve added new objects in the table there with the agegroup property.
To avoid duplication, you could use the JSON datatype for the agegroup column The values in the column could be a JSON array of integers. For example, suppose number 1 represents the age group 9-12 and number 2 would represent group 13-16. Then any habit that applies to both groups would contain the following value:
[1,2]
If a habit applies only to one group, then it would be a JSON array of just one value: