Edits history of script submission #14615 for ' Lock card (brex)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brex = {
      token: string;
    };
    /**
     * 
    Lock card
    
     * 
    Locks an existing, unlocked card. And the card owner will receive a notification about it.
    
     */
    export async function main(
      auth: Brex,
      id: string,
      body: {
        description?: string;
        reason:
          | "CARD_DAMAGED"
          | "CARD_LOST"
          | "CARD_NOT_RECEIVED"
          | "DO_NOT_NEED_PHYSICAL_CARD"
          | "DO_NOT_NEED_VIRTUAL_CARD"
          | "FRAUD"
          | "OTHER";
      },
      Idempotency_Key?: string,
    ) {
      const url = new URL(`https://platform.brexapis.com/v2/cards/${id}/lock`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          ...(Idempotency_Key ? { "Idempotency-Key": Idempotency_Key } : {}),
          "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 217 days ago