Edits history of script submission #21263 for ' Creating a Composite Item (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Creating a Composite Item
     * A new composite item can be created after creating items that we want to associcate with composite item. User can attach image for composite item by calling Different API 'https://www.zohoapis.com/inventory/v1/compositeitems/{composite_item_id}/image', passing form-data parameter image i.e. -F image=bag_s.jpg
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        name: string;
        mapped_items: {
          quantity?: number;
          item_id: number;
          line_item_id?: number;
        }[];
        description?: string;
        is_combo_product?: false | true;
        vendor_id?: number;
        purchase_rate?: number;
        purchase_description?: string;
        initial_stock?: number;
        initial_stock_rate?: number;
        tax_id?: number;
        sku: string;
        isbn?: number;
        ean?: number;
        part_number?: string;
        reorder_level?: number;
        unit?: string;
        upc?: number;
        item_type: string;
        rate: number;
        custom_fields?: { custom_field_id?: number; value?: string }[];
        account_id?: number;
        purchase_account_id?: number;
        inventory_account_id?: 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`);
      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: "POST",
        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