Edits history of script submission #21221 for ' Create a vendor payment (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a vendor payment
     * Create a payment made to your vendor and you can also apply them to bills either partially or fully.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        vendor_id?: string;
        bills?: {
          bill_payment_id?: string;
          bill_id?: string;
          amount_applied?: number;
          tax_amount_withheld?: number;
        }[];
        date?: string;
        exchange_rate?: number;
        amount: number;
        paid_through_account_id?: string;
        payment_mode?: string;
        description?: string;
        reference_number?: string;
        check_details?: string[];
        is_paid_via_print_check?: false | true;
        location_id?: string;
        custom_fields?: { index?: number; value?: string }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/vendorpayments`);
      for (const [k, v] of [["organization_id", organization_id]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + 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 235 days ago