Edits history of script submission #21971 for ' Update Recurring Invoice (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update Recurring Invoice
     * Update the recurring invoice.
     */
    export async function main(
      auth: Zoho,
      recurring_invoice_id: string,
      organization_id: string | undefined,
      body: {
        recurrence_name: string;
        reference_number?: string;
        customer_id: string;
        currency_id?: string;
        contact_persons?: string[];
        start_date?: string;
        end_date?: string;
        recurrence_frequency: "weeks";
        repeat_every?: number;
        place_of_supply?: string;
        vat_treatment?: string;
        gst_treatment?: string;
        tax_treatment?: string;
        is_reverse_charge_applied?: false | true;
        cfdi_usage?: string;
        allow_partial_payments?: false | true;
        gst_no?: string;
        location_id?: string;
        line_items?: {
          item_id?: string;
          name?: string;
          description?: string;
          rate?: number;
          quantity?: number;
          discount?: string;
          tags?: { tag_id?: string; tag_option_id?: string }[];
          tax_id?: {};
          tds_tax_id?: string;
          tax_exemption_id?: string;
          tax_treatment_code?: string;
          avatax_tax_code?: string;
          avatax_use_code?: string;
          item_total?: number;
          product_type?: string;
          hsn_or_sac?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
          location_id?: string;
          project_id?: string;
          header_name?: string;
          header_id?: string;
        }[];
        email?: string;
        custom_fields?: { value?: string; label?: string; data_type?: string }[];
        tax_id?: {};
        tax_authority_id?: string;
        payment_options?: {
          payment_gateways?: {
            configured?: false | true;
            additional_field1?: string;
            gateway_name?: string;
          }[];
        };
        tax_exemption_id?: string;
        avatax_use_code?: string;
        avatax_exempt_no?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/books/v3/recurringinvoices/${recurring_invoice_id}`,
      );
      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: "PUT",
        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