Edits history of script submission #21699 for ' List Expenses (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * List Expenses
     * List all the Expenses with pagination.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      description: string | undefined,
      reference_number: string | undefined,
      date: string | undefined,
      status: string | undefined,
      amount: string | undefined,
      account_name: string | undefined,
      customer_name: string | undefined,
      vendor_name: string | undefined,
      customer_id: string | undefined,
      vendor_id: string | undefined,
      recurring_expense_id: string | undefined,
      paid_through_account_id: string | undefined,
      search_text: string | undefined,
      sort_column: string | undefined,
      filter_by: string | undefined,
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/expenses`);
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["description", description],
        ["reference_number", reference_number],
        ["date", date],
        ["status", status],
        ["amount", amount],
        ["account_name", account_name],
        ["customer_name", customer_name],
        ["vendor_name", vendor_name],
        ["customer_id", customer_id],
        ["vendor_id", vendor_id],
        ["recurring_expense_id", recurring_expense_id],
        ["paid_through_account_id", paid_through_account_id],
        ["search_text", search_text],
        ["sort_column", sort_column],
        ["filter_by", filter_by],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Zoho-oauthtoken " + 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 235 days ago