Edits history of script submission #14102 for ' Update a webhook (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Update a webhook
     * Update a webhook and associated subscriptions.
    
    Required scopes: `webhook:read-write`.
     */
    export async function main(
      auth: Attio,
      webhook_id: string,
      body: {
        data: {
          target_url?: string;
          subscriptions?: {
            event_type:
              | "comment.created"
              | "comment.resolved"
              | "comment.unresolved"
              | "comment.deleted"
              | "list.created"
              | "list.updated"
              | "list.deleted"
              | "list-attribute.created"
              | "list-attribute.updated"
              | "list-entry.created"
              | "list-entry.updated"
              | "list-entry.deleted"
              | "object-attribute.created"
              | "object-attribute.updated"
              | "note.created"
              | "note.updated"
              | "note.deleted"
              | "record.created"
              | "record.merged"
              | "record.updated"
              | "record.deleted"
              | "task.created"
              | "task.updated"
              | "task.deleted"
              | "workspace-member.created";
            filter:
              | {
                  $or:
                    | { field: string; operator: "equals"; value: string }
                    | { field: string; operator: "not_equals"; value: string }[];
                }
              | {
                  $and:
                    | { field: string; operator: "equals"; value: string }
                    | { field: string; operator: "not_equals"; value: string }[];
                };
          }[];
        };
      },
    ) {
      const url = new URL(`https://api.attio.com/v2/webhooks/${webhook_id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago