Jun 05, 2020 04:59 AM
Hello there,
I was wondering if it is possible to search a whole workspace using the Airtable API.
The reason I need this is below:
Many thanks,
Karan
Solved! Go to Solution.
Jun 05, 2020 05:27 AM
Welcome Karan!
By default, the Airtable API does not provide the kind of inter-base calls you’re looking to make, but what you’re looking for should be possible with some development work.
A high-level overview of how this could work, looks something like:
app*****
ids listed on the API documentation).base('{Table Name}').select()
if using the Javascript library.Since all of your bases have an identical base structure and column headers, this should reduce the amount of custom code needed to parse different bases—the same API call should work for all bases, just passing in the unique base ID for each one.
Here are some potential examples for both the cURL and Javascript flavors of the API. If using the cURL API, you might find Airtable’s URL encoder to be handy for creating the filterByFormula
to select your LinkedIn records.
curl "https://api.airtable.com/v0/app*****/{Table Name}?maxRecords=3&filterByFormula=%7BLinkedIn%7D%3D%22myLinkedInId%22&view={View} \
-H "Authorization: Bearer YOUR_API_KEY"
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('app****');
base({Table Name}).select({
// Selecting the first 3 records in View:
maxRecords: 3,
view: "View",
filterByFormula: '{LinkedIn ID} = "myLinkedInId"'
})
If this answers your question, please consider marking it as “solution”. If not, I’m happy to work with you further. Thanks!
Jun 05, 2020 05:27 AM
Welcome Karan!
By default, the Airtable API does not provide the kind of inter-base calls you’re looking to make, but what you’re looking for should be possible with some development work.
A high-level overview of how this could work, looks something like:
app*****
ids listed on the API documentation).base('{Table Name}').select()
if using the Javascript library.Since all of your bases have an identical base structure and column headers, this should reduce the amount of custom code needed to parse different bases—the same API call should work for all bases, just passing in the unique base ID for each one.
Here are some potential examples for both the cURL and Javascript flavors of the API. If using the cURL API, you might find Airtable’s URL encoder to be handy for creating the filterByFormula
to select your LinkedIn records.
curl "https://api.airtable.com/v0/app*****/{Table Name}?maxRecords=3&filterByFormula=%7BLinkedIn%7D%3D%22myLinkedInId%22&view={View} \
-H "Authorization: Bearer YOUR_API_KEY"
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('app****');
base({Table Name}).select({
// Selecting the first 3 records in View:
maxRecords: 3,
view: "View",
filterByFormula: '{LinkedIn ID} = "myLinkedInId"'
})
If this answers your question, please consider marking it as “solution”. If not, I’m happy to work with you further. Thanks!
Jun 05, 2020 06:02 AM
Hey Matthew,
Many thanks for your detailed response.
If you are open to the idea of building this logic.
Would you be able to build this function for me taking into consideration that in the future I may want to change 2 variable which are:
Let me know if you are open to the idea and we can discuss further
Many thanks,
Karan
Jun 05, 2020 06:38 AM
Hey Karen,
Here is a very simple shell script that you should be able to use to get started. It has a few variables to define up top, including an array of BASES
that you can add to or remove from as your needs change. It’ll then loop over these bases and fetch the records, writing them to a baseId.json
file that you can parse/work with as needed. If you have other command line tools, you should be able to remove the ‘write to file’ bit, and pipe the results from stdout
as needed.
The one thing you’ll need to add for your specific use case is the filterByFormula
bit I mentioned above. You can tack this on to the URL
variable such that the records retrieved match whatever search criteria for LinkedIn IDs you want.
#!/bin/sh
#
fatal()
{
echo $1
exit $2
}
AIRTABLE_KEY="key***"
BASES[0]="app***"
BASES[1]="app***"
TABLE="My Table"
# Iterate through all courses listed above
for BASE in "${BASES[@]}"
do
# Assemble URL, and retrieve JSON data
URL="https://api.airtable.com/v0/$BASE/$TABLE"
STATUS=$(curl "$URL" \
-H "Authorization: Bearer $AIRTABLE_KEY" \
-o "$BASE.json" \
-s \
-w "%{http_code}")
# Check the HTTP response
if [ $STATUS -ne 200 ]
then
rm "$BASE.json"
fatal "Airtable returned a $STATUS error. Try again."
fi
done
exit 0
Jun 05, 2020 07:07 AM
Hi Karan,
I think this is kind’a what you’re looking for and here’s more about my approach.
I’ve built four of these for various clients. One was a custom block (used as the search UI) which the client built and I simply integrated the search backend. The others were either simple script block search bars or web apps. One of them even indexed multiple workspaces.
You can also read the paper that served as the requirements for tips on how you might approach this. Doing it is far more complicated than you might think, and you’ll probably be disappointed with the results unless and until you implement ranked results based on relevance.
From this point forward, I’m showing off - this Airtable search system integrates a map as the search UI…
Jun 15, 2020 09:28 AM
Hey @Karan_Setia,
If one of the answers Bill or I posted above solves your question, would you mind marking it as the “solution” so others searching the forums can easily find the information?
Thanks!
Mar 05, 2024 05:33 AM
1. Should one
1.1 search all bases in one's AirTable space, or
1.2 stick with developers who have figured out search?
2. If 1.1, under what terms would you provide instructions that would help me to this?
Sep 30, 2024 09:20 AM
I made a solution for this:
https://community.airtable.com/t5/development-apis/search-in-multiple-bases/td-p/187372