Edits history of script submission #21179 for ' Create Assemblies (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create Assemblies
     * Assemblies is the technique of putting together different components in desired quantities to produce a single commodity. These components could be goods, services and other non-inventory items of your choice.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        reference_number: string;
        date: string;
        description?: string;
        composite_item_id: number;
        composite_item_name: string;
        composite_item_sku?: string;
        quantity_to_bundle: number;
        line_items: {
          item_id: number;
          name: string;
          description?: string;
          quantity_consumed: number;
          unit?: string;
          account_id: number;
          account_name?: string;
          location_id?: string;
          location_name?: string;
          rate?: number;
        }[];
        is_completed: false | true;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/bundles`);
      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