Retrieve a record by fields

Hi, I’ve been working on a Next.js app with Airtable.

I’m trying to retrieve a single record by specifying the field (not reocrd ID provided by Airtabe).

I refered to the document below, but it only mentions the way of doing it by the record ID.

The code below is working fine, but I’d like to get a record by the specified column (eg. where “user_id” = 987813 ).

//export const getServerSideProps = async (context) => {
export async function getServerSideProps(context) {
    let todos = await table.find('rec1PDbe0ww22feo3');
    return {
        props: {
            initialTodos:  getMinifiedRecord(todos),
        },
    };
}

Thanks,

To get a specific record based on field values you need to get records for the table with filterByFormula. You will then get an array of only the records that match that condition.

Thanks for the reply.

Now I found the way to do it with select method, do you know if they have it with find method?

let todos = await table.select({maxRecords: 1,filterByFormula: "NOT({email} = '')"}).firstPage();

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.