I've created a base table on Airtable. Then from the developers/API key section, I created a token. I've copied the Token ID from the personal access tokens section and pasted it directly .env file. I filled the information correctly.
Like this ;
AIRTABLE_API_KEY=pat*************
AIRTABLE_BASE=app8Knnd8Y8wQirZX
AIRTABLE_TABLE=products
Then I tested the connection. with this code block;
const dotenv = require("dotenv");
dotenv.config();
const Airtable = require("airtable-node");
const airtable = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY })
.base(process.env.AIRTABLE_BASE)
.table(process.env.AIRTABLE_TABLE);
exports.handler = async (event, context, cb) => {
try {
const response = await airtable.list({ maxRecords: 200 });
console.log("####");
console.log(response);
console.log("####");
return {
statusCode: 200,
body: "products route",
};
} catch (error) {
console.log(error);
return {
statusCode: 500,
body: "there was an arror",
};
}
};
The output is this;
####
{
error: {
type: 'AUTHENTICATION_REQUIRED',
message: 'Authentication required'
}
}
####
Response with status 200 in 431 ms.
You can also see the scope and access section in the attachment.
I couldn't find the problem. If someone can help me, I gald.