API key resulting in issue on live server

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?

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.

1 Like

Hi Bill, This is the API code I’m using.

const airtableHeaders = new Headers()

airtableHeaders.append(‘Content-Type’, ‘application/json’)
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’,

.then(response => response.text())
.then(result => {
const returnedData = JSON.parse(result)
if (returnedData.createdTime) {
.catch(error => handleError(error))

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.