Help

API URL Query - How do I filter by date?

Topic Labels: API
8662 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Alex_Dewey
4 - Data Explorer
4 - Data Explorer

I currently have

api airtable /v0/appVhG3JD5Ko1oeJ7/Twitter%20Database/?view=20%20february%202019?api_key=MY KEY

I get
{"error":{"type":"AUTHENTICATION_REQUIRED","message":"Authentication required"}}

I’m trying to return all the Entrys with the date (written as) ‘20 February 2019’

Any ideas - I struggle reading the documentation so I’m not sure what to try

5 Replies 5
chetem
6 - Interface Innovator
6 - Interface Innovator

Perhaps a silly question, but is your API key correct and still active? Does it work without trying to filter? The authentication error makes it seem like the API key may be incorrect as it’s essentially saying you’re not authorized to view the data. Another possibility is that the API you’re using doesn’t have the right permissions to see that particular View.

Disclaimer: I’ve never personally used the Airtable API but have a developer background.

Yeah, I’m being a bit of an idiot.

https://api.airtable.com/v0/appVhG3JD5Ko1oeJ7/Twitter Database?view=Tomorrow works in postman when I add my bearer token but

https://api.airtable.com/v0/appVhG3JD5Ko1oeJ7/Twitter%20Database?view=Tomorrow?api_key=MYKEY returns

{“error”:{“type”:“AUTHENTICATION_REQUIRED”,“message”:“Authentication required”}}

so not sure where i’m going wrong between those,

What if you remove the %20 between Twitter and Database – does that work?

chetem
6 - Interface Innovator
6 - Interface Innovator

Seems strange but I did that using Insomnia (similar to Postman) and it worked fine but when the URL has %20 it errored out

Giovanni_Briggs
6 - Interface Innovator
6 - Interface Innovator

When passing your access token to the API, it should always be in the form “Bearer {MY_KEY}” where {MY_KEY} is your access token. Also, you should be placing the access token in the “Authorization” header for your request and not in a query parameter.

To filter by a given field, you have two options. One option is to create a view in your base and then use the view name in the view query parameter. For example, if the view is named “Dates after Feb 20”, you can access it via https://api.airtable.com/v0/appVhG3JD5Ko1oeJ7/Twitter%20Database?view=Dates%20after%20Feb%2020. This will only return records belonging to that view.

The other option is to use the fitlerByFormula query parameter which allows you to use Airtable formulas to fetch a subset of records. For example, you can use the ISAFTER formula to find records whose date field is after a given date.

If your date field is called My Date and you want to get all records where My Date is after “02-20-2019” then you would issue the following query: https://api.airtable.com/v0/appVhG3JD5Ko1oeJ7/Twitter%20Database?filterByFormula=IS_AFTER(%7BMy%20Date%7D,'2019-02-20')