The AirTable API (a more efficient way to integrate AirTable with Thunkable)

I’ve had the pleasure of working on a few AirTable projects recently.

One thing I’ve learned is doing stuff like this is inefficient once you start to get a lot of data.
image

You should try to limit how much data you call and the number of API calls. To update a record, you shouldn’t get all rows, loop through all rows until you find the row you need to update, then update that row.

With the AirTable API you can use things like filterByFormula to query the data in one call to reduce the data you are retrieving.

So in this video I demo the concepts of how to use the AirTable API. I will also share the set up and screen shots of the blocks.

NOTE: This is an advanced approach.

Tutorial

Demo

https://x.thunkable.com/projectPage/5fca598a8e5b21001263fad9

Thunkable API Configuration

Create Record

Read Record (using filterByFormula)

Update Record (Record ID stored on data retrieval)

Delete Record (Record ID stored on data retrieval)

7 Likes

Oooh… I think I just learned that I can use the Firebase API for making a PATCH call to update a particular child in the database. This should be very useful. Thanks, @darren!

1 Like

Great! Glad I could point that out. PATCH was recently added.

1 Like

Hello. I found this post very interesting. But I was unable to filter the data on 2 or more conditions? There’s a way?

1 Like

I’ve started using Airtable formulas to filter data. I create a view in Airtable with a specific column formula that I want and then add that view as a Data Source in Thunkable. The only (big) problem is that all of the views are named the same thing… the table base name.

But this allows me to sync Airtable with a Data Viewer List (DVL) whereas filtering by formula (below) doesn’t easily allow that.

If we could get these two issues fixed, it would be amazing:

Beyond that, I’m not sure how to add multiple filter requests to an Airtable API call. Can you give an example of what you’re trying to do?

2 Likes

Ah, you can definitely filter by formula using the Airtable API:

So you should be able to do whatever you need since formulas can be very complex and use logical gates (AND, OR).

2 Likes

The Airtable API accepts filterbyformula as a QueryParameter field which you can use the same formula used for the view filter. Of course the problem then is to loop through the records and store them in a local table to show them using DVL.

3 Likes

Yeah, just realized it really depends on whether or not you intend to use a DVL. I like my in-table view filtering for DVL support but the API filtering by formula could be used for many purposes.

3 Likes

I use a different way of filtering. I would say a more dynamic filtering

I have a table Students which is connected to a table ControlTable

All I have to do in Thunkable is to change the value in ControlTable which contains a single row. This will allow different records to be displayed from the Students table.

If you compare this image with the one above you see different students because I use the ControlTable row to filter it.

Content of ControlTable
image

2 Likes

How scalable is this approach? If me and user C are trying to filter differently at the same time, will this work?

2 Likes

I’m not sure but I guess NO. This wouldn’t work if both users filter the same time. But I tested it in a table with over 600 rows and works very fast.

2 Likes

I’d love to know a little but more about how you do this. When you say the tables are “connected” what do you mean? And how does the value in the ControlTable column achieve filtering?

Edit: Okay, I see how to link records from one table to another. How are you populating the student names in the “Students” column in the ControlTable?

2 Likes

When you choose to link your column to another record you choose this option
image

The next step is somewhat not very clear, you need to link the new column you created with a row in the other table by choosing this
image

Select all that you want. For me I selected all rows in Students table.

The next step is to create another column which is a formula column.
image

This is the filter I used IF(ControlTable=0,1,StudentGrade=ControlTable)
Which translates to
IF the row in ControlTable contains 0
THEN show all rows
ELSE
show rows where StudentGrade column matches ControlTable

The last bit of the setup is to set the Grid View which is the default to filter on the formula column
it worked for me.

2 Likes

I have a table that will contain many records in the future. With one condition I can filter, but I am not finding a way to insert the second condition. I need to filter on two fields and then save the data in the local list and then show them in DVL.

1 Like

The API does not allow more than one filterbyformula entry so you should join your both conditions in one entry.

Example: ({Num_Paese} = 48 and {Num_Categoria} = 20)

@muneer… thanks to you, I was able to remove my three extra Data Viewer Lists and just have a single one that switches between filtered columns. It’s working great!

2 Likes

Welcome boss.

1 Like

I have already tried so many ways to do
({Num_Paese} = 48 and {Num_Categoria} = 20)
but it doesn’t work.
Either there is a particular syntax (and I was wondering just that) or it is not possible to insert more than one condition.

Have you tried the AND formula that Airtable requires?

It is formatted like this:

AND({Num_Paese}=48,{Num_Categoria}=20)

If that still doesn’t work, this topic on another forum might shed some light on the issue:

(I’m not really sure how similar that issue is…)

1 Like

Yes, @tatiang
The same advice is in the Airtable community. See this post

In the other hand,
image

This shows that the numbers are keyed in as text and therefore the condition suggested by @tatiang

would read as

AND({Num_Paese}='48',{Num_Categoria}='20')