Retrieving Related Records using Ninox REST API
Hi,
I'm currently integrating an application with a Ninox database. I went though the docs and manuals, but can't find an answer to these questions.
1) Given two tables A and B, where A has one-to-many relationship with B. E.g. A is a blog post and B is a comment. Calling "GET ninox.api/tables/A/records" returns all the As and they have a field of type array which contains the IDs of the related records in B.
Is there a way to retrieve the related records too from the API in a single call, say instead of
A: { Bs: [1, 5] }, we get A: { Bs: [ {id, 1, text: "..."}, { id: 5, ... } ] }? Is it possible to send a custom query to the API that would retrieve that?
2) Is it possible to retrieve records by filtering them using "OR" logic. For example, GET A/records where id = 1, or id = 8, or id = 31?
I'' very much appreciate your help. Thanks!
3 replies
-
Hi,
Yes it is possible! You can send a GET request to a table endpoint and add "?filters=" followed by an URIencoded JSON containing your filters to receive the whole collection data.
In your situation I would send the GET request to the B table and using the A value to filter the result. Let's assume the field A is called "BlogID" in your B table, then your JSON will look something like this :
{"fields":{"BlogID":1}}
After a URI encode, it will then become : %7B%22fields%22%3A%7B%22BlogID%22%3A1%7D%7D.
In this context, your endpoint will look like this :
"https://api.ninox.com/v1/teams/TEAM_ID/databases/TABLE_ID/tables/B/records?filters=%7B%22fields%22%3A%7B%22BlogID%22%3A1%7D%7D"
... and you will receive all the data you need in one API call !
Hope this solution wors for you,
Alex
-
Hi Alex,
Thanks, that makes sense. I've got one follow-up question - if we have a one-to-many relationship such as Blog 1-* Comments, then is it possible to retrieve the comments of multiple blog posts. I suppose something like filters={fields: {BlogID: [1,4,10]}}, in other words a simple OR logic?
Also is there a way to retrieve the blog posts with their comments (not comment IDs) in a single API call? (similar to a LEFT JOIN in SQL)
Thanks,Denis
-
Hi Denis,
For your first question I'm unsure : if it is possible then I didn't find the way to do it. This is why in the example I choosed the B table endpoint, so I can filter using A, which is constant for all B comments.
To my knowledge you cannot retrieve the blog posts and their comments in a single APi call du to the fact that they are in a different table. I guess the best you can do is two API calls : one to get the blog post, then another on to get the comments.
Cheers,
Alex
Content aside
- 3 yrs agoLast active
- 3Replies
- 1204Views