Edits history of script submission #11966 for ' Create a phone number (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create a phone number
     * Create a new phone number
     */
    export async function main(
      auth: Clerk,
      body: {
        user_id?: string;
        phone_number?: string;
        verified?: false | true;
        primary?: false | true;
        reserved_for_second_factor?: false | true;
      },
    ) {
      const url = new URL(`https://api.clerk.com/v1/phone_numbers`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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