Edits history of script submission #22034 for ' Update an item (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update an item
     * Update the details of an item.
     */
    export async function main(
      auth: Zoho,
      item_id: string,
      organization_id: string | undefined,
      body: {
        group_id?: string;
        group_name?: string;
        unit?: string;
        item_type?: string;
        product_type?: string;
        is_taxable?: false | true;
        tax_id?: number;
        description?: string;
        tax_name?: string;
        tax_percentage?: number;
        tax_type?: string;
        purchase_account_id?: number;
        purchase_account_name?: string;
        account_name?: string;
        inventory_account_id?: number;
        attribute_id1?: number;
        attribute_name1?: string;
        status?: string;
        source?: string;
        name: string;
        rate?: number;
        pricebook_rate?: number;
        purchase_rate?: number;
        reorder_level?: number;
        locations?: {
          location_id?: string;
          initial_stock?: number;
          initial_stock_rate?: number;
        }[];
        vendor_id?: number;
        vendor_name?: string;
        sku?: string;
        upc?: number;
        ean?: number;
        isbn?: string;
        part_number?: string;
        attribute_option_id1?: number;
        attribute_option_name1?: number;
        image_id?: number;
        image_name?: string;
        purchase_description?: string;
        image_type?: string;
        item_tax_preferences?: { tax_id?: number; tax_specification?: string }[];
        hsn_or_sac?: string;
        sat_item_key_code?: string;
        unitkey_code?: string;
        custom_fields?: { customfield_id?: number; value?: string }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/items/${item_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