Edits history of script submission #22032 for ' Update an invoice (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update an invoice
     * Update an existing invoice. To delete a line item just remove it from the line_items list.
     */
    export async function main(
      auth: Zoho,
      invoice_id: string,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        customer_id: string;
        contact_persons?: {
          contact_person_id?: string;
          salutation?: string;
          first_name?: string;
          last_name?: string;
          email?: {};
          phone?: string;
          mobile?: string;
          is_primary_contact?: {};
        }[];
        invoice_number?: string;
        reference_number?: string;
        template_id?: string;
        date?: string;
        payment_terms?: number;
        payment_terms_label?: string;
        due_date?: string;
        discount?: number;
        is_discount_before_tax?: false | true;
        discount_type?: string;
        is_inclusive_tax?: false | true;
        exchange_rate?: number;
        recurring_invoice_id?: string;
        invoiced_estimate_id?: string;
        salesperson_name?: string;
        custom_fields?: {
          index?: number;
          show_on_pdf?: false | true;
          value?: string;
          label?: string;
        }[];
        project_id?: string;
        line_items: {
          line_item_id?: string;
          item_id?: string;
          project_id?: string;
          time_entry_ids?: string;
          expense_id?: string;
          expense_receipt_name?: string;
          name?: string;
          description?: string;
          item_order?: number;
          bcy_rate?: number;
          rate?: number;
          quantity?: number;
          unit?: string;
          discount_amount?: number;
          discount?: number;
          tax_id?: string;
          tds_tax_id?: string;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          item_total?: number;
          location_id?: string;
          hsn_or_sac?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
        }[];
        location_id?: string;
        payment_options?: {
          payment_gateways?: {
            configured?: false | true;
            additional_field1?: string;
            gateway_name?: string;
          }[];
        };
        allow_partial_payments?: false | true;
        custom_body?: string;
        custom_subject?: string;
        notes?: string;
        terms?: string;
        shipping_charge?: string;
        adjustment?: number;
        adjustment_description?: string;
        reason?: string;
        tax_authority_id?: string;
        tax_exemption_id?: string;
        avatax_use_code?: string;
        avatax_exempt_no?: string;
        vat_treatment?: string;
        tax_treatment?: string;
        billing_address_id?: number;
        shipping_address_id?: number;
        gst_no?: string;
        gst_treatment?: string;
        place_of_supply?: string;
        cfdi_usage?: string;
        cfdi_reference_type?: string;
        reference_invoice_id?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/invoices/${invoice_id}`,
      );
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["ignore_auto_number_generation", ignore_auto_number_generation],
      ]) {
        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