export type ClientIncludedIdsDto = {include: Array}; export type ClientIncludedSelectionDto = {type: 'included', ids: ClientIncludedIdsDto}; export type LinkClientsToListDto = {selection: ClientIncludedSelectionDto}; export type CreateApiListsIdClientsLinkArgs = {id: string, body: LinkClientsToListDto}; export type CreateApiListsIdClientsLinkOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Link clients to a list * * POST /lists/{id}/clients/_link */ export const createApiListsIdClientsLink = async (args: CreateApiListsIdClientsLinkArgs, options: CreateApiListsIdClientsLinkOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/lists/${encodeURIComponent(String(args.id))}/clients/_link${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 };