Edits history of script submission #14622 for ' Update an expense (brex)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brex = {
      token: string;
    };
    /**
     * Update an expense
     * Update an expense. Admin and bookkeeper have access to any expense, and regular users can only access their own.
     */
    export async function main(
      auth: Brex,
      expense_id: string,
      body: { memo?: string },
    ) {
      const url = new URL(
        `https://platform.brexapis.com/v1/expenses/card/${expense_id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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 217 days ago