Edits history of script submission #22152 for ' Updating a composite item (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Updating a composite item
     * Updating details of an existing composite item.
     */
    export async function main(
      auth: Zoho,
      composite_item_id: string,
      organization_id: string | undefined,
      body: {
        composite_item_id?: number;
        name: string;
        unit?: string;
        tax_id?: number;
        description?: string;
        tax_name?: string;
        tax_percentage?: number;
        tax_type?: string;
        purchase_account_id?: number;
        purchase_account_name?: string;
        account_id?: number;
        account_name?: string;
        inventory_account_id?: number;
        inventory_account_name?: string;
        status?: string;
        source?: string;
        is_combo_product?: false | true;
        item_type: string;
        rate: number;
        pricebook_rate?: number;
        purchase_rate?: number;
        reorder_level?: number;
        initial_stock?: number;
        initial_stock_rate?: number;
        vendor_id?: number;
        vendor_name?: string;
        stock_on_hand?: number;
        asset_value?: number;
        available_stock?: number;
        actual_available_stock?: number;
        sku: string;
        upc?: number;
        ean?: number;
        isbn?: number;
        part_number?: string;
        image_id?: number;
        image_name?: string;
        purchase_description?: string;
        custom_fields?: {
          custom_field_id?: number;
          value?: string;
          index?: number;
          label?: string;
        }[];
        mapped_items: {
          line_item_id?: number;
          item_id?: number;
          name?: string;
          rate?: number;
          purchase_rate?: number;
          sku?: string;
          image_id?: number;
          image_name?: string;
          purchase_description?: string;
          image_type?: string;
          unit?: string;
          is_combo_product?: false | true;
          description?: string;
          quantity?: number;
          stock_on_hand?: number;
          available_stock?: number;
          actual_available_stock?: number;
        }[];
        item_tax_preferences?: { tax_id?: number; tax_specification?: string }[];
        hsn_or_sac?: string;
        product_type: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/compositeitems/${composite_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