I need help with checking if a user already exists in my Airtable database by searching for their email. If the user doesn’t exist, I want to add them to the table.
Your filter syntax and method usage are the problem. I hit the same issue when building auth for our webapp. The find() method wants a record ID, not a filter - that’s why you’re getting the 404.
Double-check that your field name in curly braces matches exactly what’s in Airtable. The double quotes prevent issues with special characters in email addresses.
You’re mixing up find and select - that’s why you’re getting the 404. The find method wants a record ID, not a filter formula.
Here’s what worked for me:
database('members').select({
filterByFormula: `{userEmail} = "${userEmail}"`
}).eachPage(function page(records, fetchNextPage) {
if (records.length > 0) {
// User exists - handle accordingly
console.log('User found:', records[0]);
// Your update logic here
} else {
// Create new user
database('members').create({
userId, name, userEmail, avatar, authProvider
}, function(err, record) {
if (err) console.log(err);
res.status(200).send(record._rawJson);
});
}
}, function done(err) {
if (err) console.error(err);
});
Double-check your field name matches Airtable exactly - it’s case sensitive. Use double quotes in the filter to avoid problems with single quotes in emails.