Jan 17, 2019 03:10 PM
My “Published URL” column contains URLs of web pages.
Through API, I would like to be able to pull only the record containing a URL I supply in the call.
I am already successfully making a curl call with this…
$base = 'appPtTr2kigmLlCP8';
$table = 'Content';
$view = urlencode('Published (Robert)');
// $fields = urlencode('Published URL'); // Only return these fields, cf. https://community.airtable.com/t/using-fields-filter-in-list-of-records/940
if (!empty($offset)) {
$q_offset = '&offset='.$offset;
}
$airtable_url = 'https://api.airtable.com/v0/' . $base . '/' . $table;
// construct the url query
$url = 'https://api.airtable.com/v0/' . $base . '/' . $table . '?maxRecords=5&pagesize=1000&view='.$view . $q_offset;
But how can I make use of the relevant feature (is it filterByFormula?) to add
Elsewhere on the forum, I have seen reference like…
filterByFormula=SEARCH(‘riva’%2C+%7BLast+Name%7D)
But I have not crystallised how I would perform a query for the record with a specific “Published URL” value.
How do I do this, and what do I need to know about encoding a URL and the whole query parameter pair?
Thanks.
Jan 18, 2019 08:18 AM
filterByFormula allows you to apply an Airtable formula to limit the records that are returned. If I understand your question correctly, rather than trying to fetch a record by its Airtable record ID, you want to fetch it based on a different field value.
You can do this by doing filterByFormula={Field Name}="value"
. When your field names have a space in them, you have to wrap the name in curly brackets (you can also do this for field names that don’t have a space character, but it is not required). You should be aware that making a GET call with filterByFormula will always return a list of records, even if that list only has one value in it.
You can use this Airtable API Encoder to check how you should encode your data.
Sep 14, 2019 08:33 AM
But how can I use filterByFormula to search for a specific containing string, i.e: If I’m searching for a book name like “UX design” and the search term was just ‘ux’ how to do this?
Oct 25, 2019 09:43 AM
Reading the documentation at support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference,
your formula would look something like:
SEARCH("ux",{Field Name})
Using the Airtable API Encoder (at codepen.io/airtable/pen/rLKkYB
) suggested above, the corresponding URL would look something like:
https://api.airtable.com/v0/YOUR_BASE_ID/Table%201?fields%5B%5D=Notes&filterByFormula=SEARCH(%22ux%22%2C+Notes)&api_key=YOUR_API_KEY
Hope this helps.
-Mark
Nov 20, 2019 02:04 AM
Is it possible to somehow replace the Field Name {Field Name}
part of the URL string by the AirTable Field ID fldnXGeRDd2r9SeRb
?
I want to avoid that the code breaks in case the column is renamed.
You can find out the Field ID by opening Chrome or Firefox Code Inspector and searching for the column header’s parent div which looks like:
<div class="cell header primary read" data-columnid="fldnXGeRDd2r9SeRb" ...>
Thanks for your feedback!
Felix
May 20, 2020 06:18 AM
The above Formula is not working for the below format
“loanFk”: [
“recazeHVfHg52dTFn”
],
Oct 13, 2020 03:39 PM
How can I compose a filterByFormula string to get only records from a set of record IDs? I tried filterByFormula=“OR(RECORD_ID() = ‘recRjdJSziwMjfhO8’, RECORD_ID() = ‘recdRonUzKAIMPOxb’)”, but id doesn’t work. Thank you in advance,
Oct 14, 2020 09:59 AM
The string filterByFormula=“OR(RECORD_ID() = ‘recRjdJSziwMjfhO8’, RECORD_ID() = ‘recdRonUzKAIMPOxb’)”
works. Sorry. My bad. I had another issue.
Feb 23, 2021 04:07 PM
Hey @Momen_Zakaria Were you able to get it working?
Apr 27, 2021 10:51 PM - edited Oct 24, 2024 06:14 AM
Based on newly available functions of Regular Expressions.
Now you can use things like this.