Edits history of script submission #21207 for ' Create a recurring bill (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a recurring bill
     * Create a recurring bill.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        vendor_id: string;
        currency_id?: string;
        recurrence_name: string;
        start_date: string;
        end_date?: string;
        source_of_supply?: string;
        place_of_supply?: string;
        destination_of_supply?: string;
        gst_treatment?: string;
        gst_no?: string;
        tax_treatment?: string;
        vat_treatment?: string;
        vat_reg_no?: string;
        is_abn_quoted?: string;
        abn?: string;
        is_reverse_charge_applied?: false | true;
        pricebook_id?: string;
        is_inclusive_tax?: false | true;
        location_id?: string;
        line_items?: {
          line_item_id?: string;
          item_id?: string;
          name?: string;
          account_id?: string;
          description?: string;
          rate?: number;
          hsn_or_sac?: string;
          reverse_charge_tax_id?: string;
          location_id?: string;
          quantity?: number;
          tax_id?: string;
          tds_tax_id?: string;
          tax_treatment_code?: string;
          tax_exemption_id?: string;
          tax_exemption_code?: string;
          item_order?: number;
          product_type?: string;
          acquisition_vat_id?: string;
          reverse_charge_vat_id?: string;
          unit?: string;
          tags?: { tag_id?: number; tag_option_id?: number }[];
          is_billable?: false | true;
          project_id?: string;
          customer_id?: string;
          item_custom_fields?: {
            custom_field_id?: number;
            index?: number;
            value?: string;
            label?: string;
          }[];
          serial_numbers?: string[];
        }[];
        is_tds_applied?: false | true;
        notes?: string;
        terms?: string;
        payment_terms?: number;
        payment_terms_label?: string;
        custom_fields?: { index?: number; value?: string }[];
        discount?: string;
        discount_account_id?: string;
        is_discount_before_tax?: false | true;
        repeat_every: string;
        recurrence_frequency: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/recurringbills`);
      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