export type PluId = {list_code: string, code: string}; export type ProductSynchronizationForReward = {product_id?: string | undefined, plu_id?: PluId | undefined, reward_product_relation_type: 0 | 1}; export type CreateApiRewardsRewardIdActionsSetProductsArgs = {'Accept-Language'?: string | undefined, reward_id: string, body: {products: Array}}; export type CreateApiRewardsRewardIdActionsSetProductsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set all products that reward can be applied to * * POST /rewards/{reward_id}/actions/set-products * * Also accepts auth: basicAuth */ export const createApiRewardsRewardIdActionsSetProducts = async (args: CreateApiRewardsRewardIdActionsSetProductsArgs, options?: CreateApiRewardsRewardIdActionsSetProductsOptions) => { 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(/\/+$/, '')}/rewards/${encodeURIComponent(String(args.reward_id))}/actions/set-products${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 };