Skip to main content

Hello Guys! I need some help here, I am using javascript fetch call to get values from airtable, I want Specific field Values using filterByFormula filter…


I want only those fields where field name {TaskDate} = CurrentDate and field name {FK_UserUsageID} = PK_UserUsageID…


I see many topics about filterByFormula but i can’t understand them because of the high level formulas using in them. I try code:



fetch(airtableURL + baseInfo + tblSchedule + apikey+"?filterByFormula=AND({TaskDate} = “+ CurrentDate +”,{FK_UserUsageID} = “+PK_UserUsageID+”)")



  .then(res => res.json())



.then(res => {



console.log(res)



})



but response is:



Object {


“error”: Object {


“message”: “Authentication required”,


“type”: “AUTHENTICATION_REQUIRED”,


},


}



I also use my apikey and all that needed. Please figure out my mistakes and tell me the solution.


Thanks in advance…

Hi @Usama_Khalid - in the API documentation for your base you will see an authentication section. From here it notes:



You can authenticate to the API by providing your API key in the HTTP authorization bearer token header. Alternatively, a slightly lower-security approach is to provide your API key with the api_key query parameter.



So you can do it directly in the URL, but it would take the form:



https://api.airtable.com/v0/YOUR_BASE_ID/Table?api_key=YOUR_API_KEY&filterByFormula......



So, note that the api_key param is a query param, i.e. after the ?



It is not clear from your code, but it looks like the api_key is before the query param, so this could be the issue.



The error message is around the authorisation, not the filter by formula.


Reply