1

I'm trying to create some Notion API integrations to help my team forecast availability for staffing.

I am writing a function that should count all the times a particular user is mentioned in the people property of a database child page by using the people filter type.

Here's my code:

async function getUserAssignmentCount(database, user) {
  const response = await notion.databases.query({
    database_id: database.id,
    filter: {
      "property": "People",
      "people": {
        "contains": user.id,
      },
    },
  });

  return Object.keys(response).length;
}

For a reason I don't quite understand, this function simply returns 4 for every single user. A quick look at the API docs for the people filter property shows that you can't currently filter for people properties using the people filter…so…idk??

Can anyone think of a way to achieve this, either via something undocumented in the API or with some hacky way of getting all the user IDs from a database people property?

Thanks <3

Devin Halladay
  • 119
  • 1
  • 8

1 Answers1

2

Well, that was anticlimactic. The API is still poorly documented but I found the way:

async function getUserAssignmentCount(database, user) {
  // Returns an object with keys `object`, `results`, `next_cursor`, `has_more`
  const response = await notion.databases.query({
    database_id: database.id,
    filter: {
      "property": "People",
      "people": {
        "contains": user.id,
      },
    },
  }); 
  
  // Returns the length of the filter results
  return response.results.length;
}
Devin Halladay
  • 119
  • 1
  • 8