Edits history of script submission #21224 for ' Create an Item Group (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create an Item Group
     * A new Item Group can a be created. While creating items, user can attach image for product group by passing form-data parameter image i.e., -F image=bag_s.jpg.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        group_name: string;
        brand?: string;
        manufacturer?: string;
        unit: string;
        description?: string;
        tax_id?: number;
        attribute_name1?: string;
        items?: {
          name: string;
          rate: number;
          purchase_rate: number;
          reorder_level?: number;
          initial_stock?: number;
          initial_stock_rate?: number;
          vendor_id?: number;
          sku?: string;
          upc?: number;
          ean?: number;
          isbn?: string;
          part_number?: string;
          attribute_option_name1?: number;
          custom_fields?: { customfield_id?: number; value?: string }[];
        }[];
        attributes?: {
          id?: number;
          name?: string;
          options?: { id?: number; name?: string }[];
        }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/itemgroups`);
      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