Edits history of script submission #14623 for ' Update card (brex)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brex = {
      token: string;
    };
    /**
     * 
    Update card
    
     * 
    Update an existing vendor card
    
     */
    export async function main(
      auth: Brex,
      id: string,
      body: {
        spend_controls?: {
          spend_limit?: { amount?: number; currency?: string } & {};
          spend_duration?:
            | ("MONTHLY" & {})
            | ("QUARTERLY" & {})
            | ("YEARLY" & {})
            | ("ONE_TIME" & {});
          reason?: string;
          lock_after_date?: string;
        } & {};
        metadata?: {};
      },
      Idempotency_Key?: string,
    ) {
      const url = new URL(`https://platform.brexapis.com/v2/cards/${id}`);
    
      const response = await fetch(url, {
        method: "PUT",
        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