export type VoucherBatch = {reward_id: string, customer_id: string, store_id?: string | undefined, code?: string | undefined, value?: number | undefined, applied_date?: string | undefined, valid_from?: string | undefined, valid_to?: string | undefined, note?: string | undefined}; export type ErrorProcessing = 1 | 2; export type CreateApiVouchersBatchArgs = {'Accept-Language'?: string | undefined, body: {vouchers: Array, error_processing?: ErrorProcessing | undefined}}; export type CreateApiVouchersBatchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a batch of vouchers. * * POST /vouchers/batch * * Also accepts auth: basicAuth */ export const createApiVouchersBatch = async (args: CreateApiVouchersBatchArgs, options?: CreateApiVouchersBatchOptions) => { 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(/\/+$/, '')}/vouchers/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 };