Edits history of script submission #23135 for ' Retrieve Page Property Item (notion)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Retrieve Page Property Item
     * Get one property of a page by property ID (from Retrieve Page's `properties.<name>.id`). Title, rich text, relation and people properties come back as a paginated list of items: use it when Retrieve Page truncates them past 25 references. Paginate with `next_cursor` as `start_cursor`.
     */
    export async function main(
      auth: RT.Notion,
      page_id: string,
      property_id: string,
      start_cursor: string | undefined,
      page_size: number | undefined
    ) {
      const url = new URL(
        `https://api.notion.com/v1/pages/${page_id}/properties/${encodeURIComponent(property_id)}`
      )
      if (start_cursor !== undefined && start_cursor !== "") {
        url.searchParams.append("start_cursor", start_cursor)
      }
      if (page_size !== undefined) {
        url.searchParams.append("page_size", String(page_size))
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
          "Notion-Version": "2026-03-11",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 4 hours ago