export type ClientContactIncludedIdsDto = {include: Array}; export type ClientContactIncludedSelectionDto = {type: 'included', ids: ClientContactIncludedIdsDto}; export type LinkClientContactsToListDto = {selection: ClientContactIncludedSelectionDto}; export type CreateApiListsIdClientContactsLinkArgs = {id: string, body: LinkClientContactsToListDto}; export type CreateApiListsIdClientContactsLinkOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Link client contacts to a list * * POST /lists/{id}/client-contacts/_link */ export const createApiListsIdClientContactsLink = async (args: CreateApiListsIdClientContactsLinkArgs, options: CreateApiListsIdClientContactsLinkOptions) => { 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))}/client-contacts/_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 };