Query for specific fields in REST API

Hi.

In my Users table, i have a one to many relationship with table A, which has four fields. I would like to query Users table and load that relationship but only with two of the four fields, because i don´t need all of them. How can i do that?

Regards,
Andrés

Hi Andrés,

This is described in the documentation:

http://backendless.com/documentation/data/rest/data_relations_retrieve.htm

You can use either Single Step or Two Step relations retrieval. For REST clients you need to use the “loadRelations” query parameter and specify all the relations you need to load in there separated by comma.

Regards,
Mark

Hi Mark.

I understand that single step or two step relations retrieval load all the fields of the relationship. I want to load only some specific fields. Per example, in the phonebook diagram, i would like to get the city of some of the contacts of a specific phonebook, but only the city because i don´t need the other values for that case.

Regards,
Andrés

Hi Andrés,

To load specific properties use the “props” query parameter as described here:
http://backendless.com/documentation/data/rest/data_search_and_query.htm

Regards,
Mark

Hi Mark.

If i perform a query in table A, i can specify the properties with props, but what i want to do is perform a query in table A and get specific properties of the relationship it has with table B. ¿Is it possible?

Per example, in the phonebook diagram, i would like to retrieve the city of some of the contacts of a specific phonebook, but only the city because i don´t need the other values for that case. If i perform a query in the Contacts table, how can i specify i only want the city attribute of the Address table?

Regards,
Andrés

Hi.

Could you check this?

Regards,
Andrés

Hi Andrés,

There are several ways to do it, but with that specific table schema, it would need to be a 2 step process:

    Get a collection of objectId for the intermediate table. In the case of Phonebook, Contact and Address, that table is Contact. The query to get objectIds for all relevant contacts is:

    Phonebook[contacts].objectId=‘B2C29E08-B890-AD2B-FF21-41D422447900’

    Here’s a complete GET URL:

    http://api.backendless.com/v1/data/Contact?props=objectId&where=“Phonebook[contacts].objectId%3D’B2C29E08-B890-AD2B-FF21-41D422447900’”

    Notice I have “props=objectId” so that the server returns only objectId values. The response will look something like this:

    {“nextPage”:null,“data”:[{“address”:null,“objectId”:“681CEED2-2FCA-17AD-FF4F-44F43AE12200”},{“address”:null,“objectId”:“C2113646-BEA9-AFBB-FFBA-373F7F5FE300”}],“offset”:0,“totalObjects”:2}

    In this step you need to iterate over objectId values from step (1) and build a query that looks like this:

    Contact[address].objectId IN ( ‘ObjectID1’, ‘ObjectID2’, ‘ObjectID3’ )

    where ‘ObjectID1’, ‘ObjectID2’, ‘ObjectID3’ are objectId values from step (1). That new query needs to be sent to the Address table. Here you can also specify that you need only the “city” attribute. Here’s a complete URL:

    http://api.backendless.com/v1/data/Address?props=city&where=“Contact[address].objectId%20IN%20(%20’C2113646-BEA9-AFBB-FFBA-373F7F5FE300’%2C%20%20’681CEED2-2FCA-17AD-FF4F-44F43AE12200’%20)”

Hope this helps.

Regards,
Mark