Python advanced query table example

There are missing links in this page:

Can you provide a real example with the AdvancedQuery object?
The link goes into a massive raw file.

When I have to construct advanced queries for use in the API, I like to start in the Losant UI, construct a similar query, and then copy that out of my browser’s console. Go to the Network tab, find the request you are interested in, and pull the query out of the body.

As for this particular example, the query argument for data_table_rows.query expects a JSON object in Losant’s advanced query syntax.

So for example, say I wanted to return all data table rows where the “number” column (which is of the Number type) has a value greater than or equal to 4, OR less than or equal to 2. Using the Python REST client, that would look like …

from losantrest import Client
client = Client(auth_token=my_auth_token)
result = client.data_table_rows.query(applicationId=my_application_id, dataTableId=my_data_table_id, query={
  "$or": [
    { "number": {"$gte": 4} },
    { "number": {"$lte": 2} }
  ]})
print(result)
1 Like

It makes sense now, I was expecting a Pythonic object, instead is just the JSON syntax of the query.
Okay this makes sense now!