API call to single record

I have been using Grist’s API so far only with the fetch_table method, looping the data locally to find the relevant record.
Probably not the most efficient way when looking for a single record :sweat_smile:

I think the call method would be the solution, though I struggle to structure the call for it.

Is there a code snippet/example somewhere using call(url, json_data=None, method=None, prefix=None) to help me figure out how to make these calls?

I assume you’re talking about the Python API client. I was confused about this for a while, including when you mentioned sync_table in another post.

If you click on [source] next to any of those higher level methods in the client documentation, you’ll see an example of call in action. The generic API documentation is here, and in particular fetch_table is using the /data endpoint.

It sounds like you need the filters argument of fetch_table, e.g:

fetch_table("Table1", filters={"A": 1, "B": 2})

to list all records where A == 1 and B == 2.

Can you explain your use case in more detail? There might be a better way depending on what you’re trying to do.

1 Like

Yes, using the Python API client indeed.

Source only shows the source code and not an actual example - I wanted to see how a working example of the .call() method was implemented.

Your approach using filters on the fetch_table method does what I need! It works now :+1:

Thanks as always @alexmojaki ! :pray: