Edits history of script submission #14606 for ' List expenses (brex)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brex = {
      token: string;
    };
    /**
     * List expenses
     * List expenses under the same account. Admin and bookkeeper have access to any expense, and regular users can only access their own.
     */
    export async function main(
      auth: Brex,
      expand__: string | undefined,
      user_id__: string | undefined,
      parent_expense_id__: string | undefined,
      budget_id__: string | undefined,
      spending_entity_id__: string | undefined,
      expense_type__: string | undefined,
      status__: string | undefined,
      payment_status__: string | undefined,
      purchased_at_start: string | undefined,
      purchased_at_end: string | undefined,
      updated_at_start: string | undefined,
      updated_at_end: string | undefined,
      load_custom_fields: string | undefined,
      cursor: string | undefined,
      limit: string | undefined,
    ) {
      const url = new URL(`https://platform.brexapis.com/v1/expenses`);
      for (const [k, v] of [
        ["expand[]", expand__],
        ["user_id[]", user_id__],
        ["parent_expense_id[]", parent_expense_id__],
        ["budget_id[]", budget_id__],
        ["spending_entity_id[]", spending_entity_id__],
        ["expense_type[]", expense_type__],
        ["status[]", status__],
        ["payment_status[]", payment_status__],
        ["purchased_at_start", purchased_at_start],
        ["purchased_at_end", purchased_at_end],
        ["updated_at_start", updated_at_start],
        ["updated_at_end", updated_at_end],
        ["load_custom_fields", load_custom_fields],
        ["cursor", cursor],
        ["limit", limit],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 217 days ago