Problem with the API: filters and the booleans

I have a big problem and I haven’t been able to find a solution or the logic behind it.

Goal: Integrate Baserow with Webstudio and use the filters available in the API to work with the forms provided by Webstudio, obtaining filtered data according to the selected checkboxes and the search, just like in John Siciliano’s video.

Usage context:

  • I have everything set up exactly as shown in the video.

  • In the table I’m using there are 51 rows; I need to filter two single‑select columns and one Boolean column.

  • Only one row has the Boolean field enabled.

Works correctly (single‑select columns)

  • When configuring filters of type single_select_equal there is no problem; it works correctly even when no filter is active, showing all rows (51).

  • The API response is ({ "ok": true, "status": 200, "statusText": "OK", "data": { "count": 51, ....

  • The JSON for the filters is:

{
  "filter_type": "AND",
  "filters": [
    {
      "type": "single_select_equal",
      "field": 8813677,
      "value": "${system.search.disponibles && 8272394}"
    },
    {
      "type": "single_select_equal",
      "field": 8234535,
      "value": "${system.search.tecnica && 8312563}"
    }
  ],
  "groups": []
}

Erratic behavior (Boolean columns)

  • If I add a filter of type boolean (or a compatible type), when no filter is active all rows appear except the one where the Boolean is enabled, even though the filter isn’t active.

  • The API response is ({ "ok": true, "status": 200, "statusText": "OK", "data": { "count": 50, ....

  • The JSON for the filters is:

{
  "filter_type": "AND",
  "filters": [
    {
      "type": "single_select_equal",
      "field": 8813677,
      "value": "${system.search.disponibles && 8272394}"
    },
    {
      "type": "single_select_equal",
      "field": 8234535,
      "value": "${system.search.tecnica && 8312563}"
    },
    {
      "type": "boolean",
      "field": 8813666,
      "value": "${system.search.complemento ? 1 : ''}"
    }
  ],
  "groups": []
}
  • I’ve tried every operator, even breaking the intended logic, such as ${system.search.complemento ? 1 : ''}, ${system.search.complemento ? 1 : 0}, ${system.search.complemento && 1}, ${system.search.complemento || 1}, ${system.search.complemento == 1}, {"type":"empty"}, {"type":"no_empty"}, etc.

  • The behavior remains inconsistent and I can’t figure out why.

  • This happens even when using only the Boolean filters, employing filter groups.

I hope you can help me, point out any mistakes I’m making, or guide me on how to configure Boolean filters correctly.

Thank you very much in advance.

Hi @khalil.io,

I think the confusion is that you consider a filter condition (“filter”) to not be active, even if you are passing it in. But when filtering Boolean fields you simply filter for “all true” or “all false” as shown in the Baserow UI:

If you don’t want the filter to be applied, you should not send it.

1 Like

Hi @petrs,

Thank you very much for the response!

I definitely misinterpreted the logic of ${system.search.boolean ? 1 : 0}, thinking it would result in ${system.search.boolean ? 1 : [all disabled]}.

How would you advise me to achieve my goal using best practices? What alternative exists for these cases?

I’ve been testing, and a solution that occurred to me (since I need to use booleans to filter content) was to add a formula column (8813456) that sets:

  • If the boolean (8813666) is true then write: 1 – 0
  • If the boolean (8813666) is false then write: 0
  • Formula: if(field('Complemento'), '1 - 0', '0')

To build the filter with dynamic values, it should contain ‘1’ to show the trues and ‘0’ to show everything. It ends up looking like this:

{
  "filter_type": "AND",
  "filters": [
    {
      "type": "contains",
      "field": 8813456,
      "value": "${system.search.complemento ? 1 : 0}"
    }
  ],
  "groups": []
}

Greetings and thank you again!

1 Like

The best practice is to dynamically add or not add the filter condition part in the JSON. But if that’s problematic, the workaround with formula field seem great:)

1 Like