Edits history of script submission #21980 for ' Update a Quote (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a Quote
     * Update an existing quote. To delete a line item just remove it from the line_items list.
     */
    export async function main(
      auth: Zoho,
      estimate_id: string,
      ignore_auto_number_generation: string | undefined,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        customer_id: string;
        contact_persons?: string[];
        template_id?: string;
        place_of_supply?: string;
        gst_treatment?: string;
        tax_treatment?: string;
        gst_no?: string;
        estimate_number?: string;
        reference_number?: string;
        date?: string;
        expiry_date?: string;
        exchange_rate?: number;
        discount?: number;
        is_discount_before_tax?: false | true;
        discount_type?: string;
        is_inclusive_tax?: false | true;
        custom_body?: string;
        custom_subject?: string;
        salesperson_name?: string;
        custom_fields: { label?: string; value?: string }[];
        line_items?: {
          item_id: string;
          name?: string;
          description?: string;
          item_order?: number;
          rate: number;
          quantity: number;
          product_type?: string;
          hsn_or_sac?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
          unit?: string;
          discount_amount?: number;
          discount?: number;
          tax_id?: string;
          tds_tax_id?: string;
          tax_exemption_id?: string;
          avatax_tax_code?: string;
          avatax_use_code?: string;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          item_total?: number;
        }[];
        notes?: string;
        terms?: string;
        shipping_charge?: string;
        adjustment?: number;
        adjustment_description?: string;
        tax_id?: string;
        tax_exemption_id?: string;
        tax_authority_id?: string;
        avatax_use_code?: string;
        avatax_tax_code?: string;
        avatax_exempt_no?: string;
        vat_treatment?: string;
        project_id?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/billing/v1/estimates/${estimate_id}`,
      );
      for (const [k, v] of [
        ["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: {
          "X-com-zoho-subscriptions-organizationid":
            X_com_zoho_subscriptions_organizationid,
          "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