Edits history of script submission #11946 for ' Update Subscriber (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * Update Subscriber
     *
     */
    export async function main(
      auth: Buttondown,
      id_or_email: string,
      body: {
        email_address?: string;
        notes?: string;
        metadata?: {};
        tags?: string[];
        referrer_url?: string;
        type?:
          | "regular"
          | "premium"
          | "churning"
          | "past_due"
          | "gifted"
          | "unpaid"
          | "churned"
          | "unactivated"
          | "unsubscribed"
          | "malformed"
          | "complained"
          | "undeliverable"
          | "spammy"
          | "removed"
          | "trialed"
          | "disabled"
          | "paused"
          | "disposable";
        unsubscription_reason?: string;
      },
    ) {
      const url = new URL(
        `https://api.buttondown.com/v1/subscribers/${id_or_email}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Token " + 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 428 days ago