export type V4ExperimentAttachRequest = {group_id: string}; export type CreateApiExperimentsExperimentIdUsersUserIdArgs = {experiment_id: string, user_id: string, body: V4ExperimentAttachRequest}; export type CreateApiExperimentsExperimentIdUsersUserIdOptions = {baseUrl?: string | undefined, secretAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Attach a user to an experiment group * * POST /experiments/{experiment_id}/users/{user_id} */ export const createApiExperimentsExperimentIdUsersUserId = async (args: CreateApiExperimentsExperimentIdUsersUserIdArgs, options?: CreateApiExperimentsExperimentIdUsersUserIdOptions) => { const {baseUrl = "https://api.qonversion.io/v4", fetch: fetchFn = fetch, secretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (secretAuth !== undefined) headers.set('authorization', `Bearer ${secretAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/experiments/${encodeURIComponent(String(args.experiment_id))}/users/${encodeURIComponent(String(args.user_id))}${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 };