Edits history of script submission #21989 for ' Update a credit note (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a credit note
     * To update the details of an existing creditnote.
     */
    export async function main(
      auth: Zoho,
      creditnote_id: string,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        customer_id: string;
        contact_persons?: string[];
        date: string;
        is_draft?: false | true;
        exchange_rate?: string;
        line_items: {
          item_id?: string;
          line_item_id?: string;
          account_id?: string;
          name?: string;
          description?: string;
          item_order?: number;
          rate?: number;
          quantity?: number;
          unit?: string;
          discount?: number;
          tax_id?: string;
          tds_tax_id?: string;
          tax_exemption_id?: string;
          tax_exemption_code?: string;
          avatax_use_code?: string;
          avatax_tax_code?: string;
          product_type?: string;
          hsn_or_sac?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
          item_custom_fields?: { value?: string; index?: number; label?: string }[];
          location_id?: string;
          location_name?: string;
          serial_numbers?: string;
          invoice_id?: string;
          invoice_item_id?: string;
          is_item_shipped?: false | true;
          is_returned_to_stock?: false | true;
          salesreturn_item_id?: string;
        }[];
        location_id?: string;
        creditnote_number: string;
        gst_treatment?: string;
        tax_treatment?: string;
        gst_no?: string;
        cfdi_usage?: string;
        cfdi_reference_type?: string;
        place_of_supply?: string;
        ignore_auto_number_generation?: false | true;
        reference_number?: string;
        custom_fields?: { value?: string; index?: number; label?: string }[];
        notes?: string;
        terms?: string;
        template_id?: string;
        tax_id?: string;
        tax_authority_id?: string;
        tax_exemption_id?: string;
        avatax_use_code?: string;
        avatax_exempt_no?: string;
        vat_treatment?: string;
        is_inclusive_tax?: false | true;
        item_id?: string;
        account_id?: string;
        name?: string;
        avatax_tax_code?: string;
        description?: string;
        unit?: string;
        rate?: number;
        quantity?: number;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/creditnotes/${creditnote_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