Edits history of script submission #23137 for ' Move Page to Trash or Restore (notion)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Move Page to Trash or Restore
     * Move a page to the trash (`in_trash` true), or restore it from the trash (`in_trash` false). Trashed pages can be restored until Notion empties the trash.
     */
    export async function main(
      auth: RT.Notion,
      page_id: string,
      in_trash: boolean = true
    ) {
      const response = await fetch(`https://api.notion.com/v1/pages/${page_id}`, {
        method: "PATCH",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
          "Notion-Version": "2026-03-11",
        },
        body: JSON.stringify({ in_trash }),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago