Python requests : filter rows on table-type field

Hi !
I succesfuly managed to query rows from my table using your python documentation (which is great, thanks)
Now, I’m trying to filter these rows using the filter__{field}__{filter} params key. It works on single ligne type fields but I did not succed with the link-to-table type. Does it require a different syntax ?
This is the code I used, the Client field is a link-to-table type:

response = requests.get(
    "https://api.baserow.io/api/database/rows/table/88561/?user_field_names=true",
    headers={
        "Authorization": f"Token {token}"
    },
    params={
        "filter__Clients__equal" : "Mister XX"
    }
)
2 Likes

Hey there :slight_smile:

Great to see that you are using our API!

So as you already probably figured, the syntax for the param is filter_<name-of-the-field>_<name-of-the-filter> and in this case you are trying to filter over Clients with an equal filter.
Clients is a link to table field and the reason why it doesn’t work is because link to table fields don’t have an equal filter.

The options you have are:

  • link_row_has
  • link_row_has_not
  • link_row_contains
  • link_row_not_contains
  • empty
  • not_empty

If you are ever unsure what types of filters your field supports you can look at the API documentation (REST API documentation // Baserow) under <your-database-name>fields you can see a list of available filters for each field that you have in that database:

Screenshot 2022-08-08 at 09.03.06

Hope that helps!

2 Likes

Thanks for your answer Alex.
I tried the link_row_contains method instead, but the result is still un-filtered.

response = requests.get(
    "https://api.baserow.io/api/database/rows/table/88561/?user_field_names=true",
    headers={
        "Authorization": f"Token {token}"
    },
    params={
        "filter__Clients__link_row_contains" : "XX"
    }
)

Hey there,

Interesting! Maybe you can double check the name of your field and look out for any spelling mistakes?

I have prepared a demo for you to showcase that this should be possible:
A public grid view I created: Baserow // Baserow

The request which will filter the link row value:
GET https://api.baserow.io/api/database/views/grid/W5coOuLw9VZAhzfcoOS-u0hsky-KprynH1LFVBociSE/public/rows/?filter__field_550763__link_row_contains=hello

1 Like

Hi @Alex,

Ok then… without the User Field Names syntax it totally works.

response = requests.get(
    "https://api.baserow.io/api/database/rows/table/88561/",
    headers={
        "Authorization": f"Token {token}"
    },
    params={
        "filter__field_543116__link_row_contains" : "Mister XX"
    }
)

I wish I could avoid that for code clarity but it is not a big deal.
Thank you !

1 Like

Hey @Nicolas,

Hmm so you are saying that user_field_names are working fine on text fields but they are not working on link row fields?

If that is the case then this might actually be a bug worth investigating.

Hey @Nicolas ,

Me again :smiley:

Just had a talk to the other devs, it looks like this isn’t part of what user_field_names is supposed to do. At the moment this flags only influences the response, so all the field ids are swapped by their names in the response. This does not mean that you can use the names in the filters as well instead of the ids if you set the flag.

I am curious to understand why this worked for you on the text field? It shouldn’t have, are you sure you used the name? Could you maybe provide a public url that does exactly that and it works?

No worries if it was just a mixup!

I’ll be glad to help you with another example. How do you create a public link ?

@Nicolas I made you a little gif that shows how to create a public view :slight_smile:
create-public-view

can’t believe you made that gif just for me :smile:
There you go : https://baserow.io/public/grid/g2I-clLLPkjqWYuOLfdgG6zvKpyoazzRaTfy2RfhMmw

@Nicolas
Great! What I meant is, I don’t think you can ever filter in the url using user field names, regardless of what field type, this just doesn’t work in general.

This does not work:
https://api.baserow.io/api/database/views/grid/g2I-clLLPkjqWYuOLfdgG6zvKpyoazzRaTfy2RfhMmw/public/rows/?user_field_names=True&filter__Name__equal=DOC1

This does work:
https://api.baserow.io/api/database/views/grid/g2I-clLLPkjqWYuOLfdgG6zvKpyoazzRaTfy2RfhMmw/public/rows/?filter__field_560625__equal=DOC1

You’re right.
Ok, now I know how to handle the filter.
thanks for your help.