Edits history of script submission #22027 for ' Update an Item Group (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update an Item Group
     * Updates the details of an existing Item Group.
     */
    export async function main(
      auth: Zoho,
      itemgroup_id: string,
      organization_id: string | undefined,
      body: {
        group_name: string;
        brand?: string;
        manufacturer?: string;
        unit: string;
        description?: string;
        tax_id?: number;
        attribute_name1?: string;
        custom_fields?: { customfield_id?: number; value?: string }[];
        name: string;
        rate: number;
        purchase_rate: number;
        sku: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/itemgroups/${itemgroup_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