export type ItemType = 0 | 1 | 2 | 3; export type CreateItemBarcodeBulkRequest = {barcode?: (string | null) | undefined, unit?: (string | null) | undefined, quantity?: number | undefined, netWeight?: number | undefined, grossWeight?: number | undefined, unitFactor?: number | undefined}; export type CreateItemBulkRequest = {code?: (string | null) | undefined, name?: (string | null) | undefined, type?: ItemType | undefined, inventUnitId?: (string | null) | undefined, vendor?: (string | null) | undefined, ownerAccountCode?: (string | null) | undefined, imageUrl?: (string | null) | undefined, properties?: ({[key: string]: string} | null) | undefined, barcodes?: (Array | null) | undefined}; export type CreateApiV1ItemsBulkArgs = {serviceId?: string | undefined, forceOverwriteOwner?: boolean | undefined, Account: unknown, body: Array}; export type CreateApiV1ItemsBulkOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Bulk upsert items masterdata. * Accepts a JSON array of items. Items are matched by `code` — existing items are updated, new ones are created. * Items missing `code` or `name` are silently skipped; validate your payload before sending. * Unit identifiers (`inventUnitId`, barcode `unit`) are normalised to lowercase and auto-created if they do not exist. * The server processes large arrays in internal batches of 5 000 items. Endpoint timeout is 5 minutes. * * POST /v1/Items/bulk */ export const createApiV1ItemsBulk = async (args: CreateApiV1ItemsBulkArgs, options: CreateApiV1ItemsBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json-patch+json; x-api-version=1.0") if (args.serviceId != null) query.append("serviceId", String(args.serviceId)) if (args.forceOverwriteOwner != null) query.append("forceOverwriteOwner", String(args.forceOverwriteOwner)) if (args.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Items/bulk${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };