Edits history of script submission #11880 for ' Create User (buttondown)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Buttondown = {
      token: string;
    };
    /**
     * Create User
     *
     */
    export async function main(
      auth: Buttondown,
      body: {
        permissions: {
          subscriber?: "none" | "read" | "write";
          email?: "none" | "read" | "write";
          sending?: "none" | "read" | "write";
          styling?: "none" | "read" | "write";
          administrivia?: "none" | "read" | "write";
          automations?: "none" | "read" | "write";
          surveys?: "none" | "read" | "write";
        };
        email_address: string;
      },
    ) {
      const url = new URL(`https://api.buttondown.com/v1/users`);
    
      const response = await fetch(url, {
        method: "POST",
        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