Support Topics Documentation Slack YouTube Blog

Codeless APIs - load a table based on a property from another table

Hey guys,

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.

Any guidance would be much appreciated.

Thanks,
Eoin

Hello @Eoin_Doyle

Try changing your whereClause to age> = 5 and age <= 8
https://monosnap.com/direct/eKusWlc1hnSIn3dtgqSIw4hpwnI3F7
Also, can you clarify why you are using User Id in your whereClause?

Regards,
Inna

Thanks for this Inna.

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?

Many thanks,
Eoin

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

Yes, in my example all habits are in one table. Here is my data schema. https://monosnap.com/direct/oMxE8L77bdmTkajhiKC4Zc6p5aeqJ2

If I understood you correctly and you want to get only unique related objects with habits, then you can use distinct = true
https://monosnap.com/direct/grk5vFhW5YreObWeIlupnY89rqLDme

Regards,
Inna

Thanks for this Inna. I will take a look at it this evening (my timezone is GMT) and let you know how I get on.

E

Thanks for this Inna.

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<=’.

Also I’ve followed your table schema with the relation too.

This is my first attempt at developing something myself so apologies for all the rookie questions :smiley:

My App ID is C209BEBE-88E7-1122-FF98-41304F96CA00 in case this helps you understand what i’m doing.

Thanks,
Eoin

By looking at the error, it appears the values for your method arguments are missing.

Do’h. That’s a real newbie mistake there. Thanks for pointing that out.

Thanks,
E

Hi @Inna_Shkolnaya,

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.

Thanks,
Eoin

Hi Eoin,

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?

Regards,
Mark

Hi Mark,

Apologies for my delayed response - the day job got in the way yesterday.

No problem I will try my best to lay it all our here - apologies for the long message.

My app is a habit tracker and it is designed for elite sporting academies. The user groups at MVP will be aged 5-8, 9-12 and 13-16.

When a user first signs up for the app, they will have to choose which habits to track for the 1st month and in month 2 they will add in an additional habit. In month 3 they drop 1 or more of the habits and replace these from the available options of habits.

Users aged 5-8 will choose 4 habits to track for month 1, 5 in month 2 and in month 3 they will drop 1 habit and replace it with another habit to give them a total of 5 habits to track in month 3 and they will track a maximum of 5 habits through months 4-12, replacing habits each month as they see fit.

Users aged 9-12 will track 6 habits in month 1, 7 habits in month 2, and 7 in months 3-12. The users will replace habits as they see fit but will track a maximum of 7.

Users aged 13-16 will track 8 habits in month 1, 9 in month 2 and 9 habits in months 3-12. The users will replace habits as they see fit but will track a maximum of 9.

If the user is aged 5-8 they can choose from the following habits to track:
Sleep
Water
Food
Fruit & veg
Time in nature
Tidyness
Brush your teeth
Fundamentals
New Skills
Learning
Play time
Gratitude

If the user is aged 9-12 they can choose from the following habits:
Sleep
Water
Food
Fruit & veg
Time in nature
Tidyness
Brush your teeth
Fundamentals
New Skills
Learning
Play time
Gratitude
Mindfulness
Reflection
Problem Solving
Self Expression
Relationships
Achievement
Exercise

If the user is aged 13-16, they can choose from the following habits to track:
Sleep
Water
Food
Fruit & veg
Time in nature
Tidyness
Brush your teeth
Fundamentals
New Skills
Learning
Play time
Gratitude
Mindfulness
Reflection
Problem Solving
Self Expression
Relationships
Achievement
Exercise
Limit screen time

Therefore the API call i’m looking to build is part of the onboarding/sign-up process in the app. The API call would display the habits that are available for the users age and the user would select from this list the habits that they want to track for that given month. The habits that they are tracking in a given month would then be stored in Backendless and that’s where the API call that is outlined above in this thread comes in - with the relation in the table schema this should identify the habits that are assigned to the user profile. However the API call that I still need to make, will display the habits available for the user age for them to choose which ones they want to track.

I hope this clarifies what I’m looking to make here. Please let me know if any of this isn’t clear enough.

Many thanks for your help and patience with this too,
Eoin

Hi Eoin,

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?

Kind regards,
Mark

Hi Mark,

Yes my app id is: C209BEBE-88E7-1122-FF98-41304F96CA00

Note that tables habits_5_8, habits_9_12 and habits_13_16 are no longer needed but I haven’t removed them as yet.

Appreciate the help,
Eoin

Hi Eoin,

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.

Regards,
Mark

Hi Mark,

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.

Thanks,
Eoin

Hi Eoin,

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:

[1]

Just an idea…

Regards,
Mark

Thanks for the tip Mark,

I’ve amended the table habits to include this and used 1=5-8, 2=9-12 and 3=13-16.

Thanks,
Eoin