Oct 29, 2020 06:09 AM
We’ve built a custom API call to push form data into Airtable, this works fine when working on my localhost environment but when deployed to our staging site we get the following error returned from the API
{"error":{"type":"AUTHENTICATION_REQUIRED","message":"Authentication required"}}
There is no difference between any of the code base, the tables it references or the API keys.
Is there some additional setup needed to allow these requests to be pushed up from a specific domain?
Oct 29, 2020 06:28 AM
Hi Shane and welcome to the community!
This suggests – however implausible it may seem – that whatever authentication method you have built into your API, it is probably not relying on those credentials when testing locally. Instead, it is more likely that it works on your local system because a security context exists [already] and is masking the failure of your API’s authentication process.
Of course, this is is purely hypothetical because I cannot see your API code.
Oct 30, 2020 01:54 AM
Hi Bill, This is the API code I’m using.
const airtableHeaders = new Headers()
airtableHeaders.append(‘Content-Type’, ‘application/json’)
airtableHeaders.append(
‘Authorization’,
Bearer ${process.env.AIRTABLE_API_KEY}
)
const fieldsPrep = JSON.parse(fieldsOuter)
const raw = JSON.stringify(fieldsPrep)
const requestOptions = {
method: ‘POST’,
headers: airtableHeaders,
body: raw,
redirect: ‘follow’,
}
fetch(
https://api.airtable.com/v0/app1234567890/${airtableFormId}
,
requestOptions
)
.then(response => response.text())
.then(result => {
const returnedData = JSON.parse(result)
if (returnedData.createdTime) {
setSubmitted(true)
}
})
.catch(error => handleError(error))
Nov 12, 2020 05:06 AM
Have you set this variable with your api key on the server?
If you are pulling code from a repository, the code setting the api key probably wasn’t in the repository for security reasons.