Like the last Notion example I posted, this one interfaces with my giant, singular Tasks database in Notion. This one selects one task at random (that does not have a status of Done or Archive).
Install notion-random-task
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let {data} = await post(
  `https://api.notion.com/v1/databases/${databaseID}/query`,
{
  "filter": {
    "and": [
      {
        "property": "Status",
        "select": {
          "does_not_equal": "Done"
        }
      },
      {
        "property": "Status",
        "select": {
          "does_not_equal": "Archive"
        }
      }
    ]
  },
  page_size: 100
},
{
  headers: {
    Authorization: `Bearer ${notionToken}`,
    "Content-Type": "application/json",
    "Notion-Version": "2021-05-13"
  }
})
let tasks = data.results
let task = tasks[Math.floor(Math.random() * tasks.length)];
let pageID = task.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)
await focusTab(pageURL, "Google Chrome Beta")
I also created one that only queries for tasks with no status (the "inbox")...
Install notion-random-from-inbox
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let {data} = await post(
  `https://api.notion.com/v1/databases/${databaseID}/query`,
{
  "filter": 
  {
    "property": "Status",
    "select": {
      "is_empty": true
    }
  },
  page_size: 50
},
{
  headers: {
    Authorization: `Bearer ${notionToken}`,
    "Content-Type": "application/json",
    "Notion-Version": "2021-05-13"
  }
})
let tasks = data.results
let task = tasks[Math.floor(Math.random() * tasks.length)];
let pageID = task.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)
await focusTab(pageURL, "Google Chrome Beta")
~Is there a better way to open the link in a browser? I stole this method from Ian Jones.~