Edits history of script submission #5888 for ' Create a new contact (resend)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Resend = {
      token: string;
    };
    /**
     * Create a new contact
     *
     */
    export async function main(
      auth: Resend,
      audience_id: string,
      body: {
        email: string;
        first_name?: string;
        last_name?: string;
        unsubscribed?: boolean;
        audience_id?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.resend.com/audiences/${audience_id}/contacts`
      );
    
      const response = await fetch(url, {
        method: "POST",
        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 399 days ago

  • nativets
    type Resend = {
      token: string;
    };
    /**
     * Create a new contact
     *
     */
    export async function main(
      auth: Resend,
      audience_id: string,
      body: {
        email: string;
        first_name?: string;
        last_name?: string;
        unsubscribed?: boolean;
        audience_id?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.resend.com/audiences/${audience_id}/contacts`
      );
    
      const response = await fetch(url, {
        method: "POST",
        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 826 days ago