Edits history of script submission #21981 for ' Update a Sales Order (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a Sales Order
     * Updates a new Sales Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto sales order number generation for this sales order. This mandates the Sales Order number to be entered. Allowed Values true and false.
     */
    export async function main(
      auth: Zoho,
      salesorder_id: string,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        salesorder_number: string;
        date?: string;
        shipment_date?: string;
        custom_fields?: {
          custom_field_id?: number;
          index?: number;
          label?: string;
          value?: string;
        }[];
        reference_number?: string;
        customer_id: number;
        contact_persons?: { contact_person_id?: number }[];
        discount?: number;
        is_discount_before_tax?: false | true;
        discount_type?: string;
        delivery_method?: string;
        shipping_charge?: number;
        adjustment?: number;
        adjustment_description?: string;
        pricebook_id?: string;
        notes?: string;
        salesperson_name?: string;
        terms?: string;
        exchange_rate?: number;
        line_items: {
          line_item_id?: number;
          item_id?: number;
          name?: string;
          description?: string;
          rate?: number;
          quantity?: number;
          unit?: string;
          tax_id?: number;
          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;
        billing_address_id?: number;
        shipping_address_id?: number;
        place_of_supply?: string;
        gst_treatment?: string;
        gst_no?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/salesorders/${salesorder_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