Edits history of script submission #23074 for ' Update Page Properties (notion)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Page Properties
     * Set a page's title, icon, or property values. `properties` takes Notion property values keyed by name, e.g. {"Status": {"status": {"name": "Done"}}}; properties left out are unchanged.
     */
    export async function main(
      auth: RT.Notion,
      page_id: string,
      title: string | undefined,
      properties: { [key: string]: any } | undefined,
      icon_emoji: string | undefined
    ) {
      const body: { [key: string]: any } = { properties: { ...properties } }
      if (title !== undefined && title !== "") {
        body.properties.title = { title: [{ text: { content: title } }] }
      }
      if (icon_emoji !== undefined && icon_emoji !== "") {
        body.icon = { type: "emoji", emoji: icon_emoji }
      }
    
      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(body),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 days ago