1
import { Client } from "@notionhq/client";

export default async function handler(req, res) {
  const notion = new Client({ auth: process.env.NOTION_API_KEY });
  const database = await notion.databases.query({
    database_id: process.env.NOTION_DB_KEY,
    filter: {
      status: "Completed",
     
    },
  });
 
  res.send(database);
}

I am trying to filter by status but i couldnt understand how to filter by status

Wice
  • 11
  • 1

1 Answers1

0

The status filter expect a StatusPropertyFilter object, so you should define the filter as following.

filter: {
  status: {
    equals: "Completed"
  },
},

And beyond equals you can also filtering by does_not_equal, is_empty, is_not_empty .

So the whole code will looks like this

import { Client } from "@notionhq/client";

export default async function handler(req, res) {
  const notion = new Client({ auth: process.env.NOTION_API_KEY });
  const database = await notion.databases.query({
    database_id: process.env.NOTION_DB_KEY,
    filter: {
      status: {
        equals: "Completed"
      },
    },
  });
 
  res.send(database);
}

You can also check the notion-sdk-js source code in Github for more information

https://github.com/makenotion/notion-sdk-js/blob/main/src/api-endpoints.ts#L9251

donjade
  • 1
  • 1
  • 1