export type PluId = {list_code: string, code: string}; export type PropertyRecord = {property_record_id?: string | undefined, property_id: string, property_name?: string | undefined, property_value?: (string | number | number | boolean | Array | Record) | undefined, last_change?: string | undefined}; export type Price = {currency_id: string, value: number}; export type Tag = {tag_id?: string | undefined, name?: string | undefined, text_id?: string | undefined, state?: (0 | 1 | 2) | undefined, last_change?: string | undefined}; export type ProductBatch = {product_id?: string | undefined, name: string, code?: string | undefined, plu_ids: Array, product_group_id?: string | undefined, product_group_external_id?: string | undefined, product_brand_id?: string | undefined, product_brand_external_id?: string | undefined, store_id?: string | undefined, partner_id?: string | undefined, property_records?: Array | undefined, prices?: Array | undefined, tags?: Array | undefined, state?: (0 | 1) | undefined}; export type ErrorProcessing = 1 | 2; export type CreateApiProductsBatchArgs = {'Accept-Language'?: string | undefined, body: {products: Array, error_processing?: ErrorProcessing | undefined}}; export type CreateApiProductsBatchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a batch of products * * POST /products/batch * * Also accepts auth: basicAuth */ export const createApiProductsBatch = async (args: CreateApiProductsBatchArgs, options?: CreateApiProductsBatchOptions) => { const {baseUrl = "https://sandbox.crmcarecloud.com/webservice/rest-api/enterprise-interface/v1.0", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/batch${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 };