Edits history of script submission #21698 for ' List Customer Payments (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * List Customer Payments
     * List all the payments made by your customer.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      customer_name: string | undefined,
      reference_number: string | undefined,
      date: string | undefined,
      amount: string | undefined,
      notes: string | undefined,
      payment_mode: string | undefined,
      filter_by: string | undefined,
      sort_column: string | undefined,
      search_text: string | undefined,
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/customerpayments`);
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["customer_name", customer_name],
        ["reference_number", reference_number],
        ["date", date],
        ["amount", amount],
        ["notes", notes],
        ["payment_mode", payment_mode],
        ["filter_by", filter_by],
        ["sort_column", sort_column],
        ["search_text", search_text],
      ]) {
        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