export type ApiPreference = {id?: number | undefined, publicName?: (string | null) | undefined, privateName?: (string | null) | undefined, isPreference?: boolean | undefined, order?: (string | null) | undefined, isPublic?: boolean | undefined, categoryId?: number | undefined, preferenceCount?: number | undefined, created?: string | undefined, lastModified?: string | undefined, isOptedIn?: (boolean | null) | undefined, preferences?: (Array | null) | undefined}; export type CreateApiV2PreferencesArgs = {body: ApiPreference}; export type CreateApiV2PreferencesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new preference or a new preference category. * * POST /v2/preferences */ export const createApiV2Preferences = async (args: CreateApiV2PreferencesArgs, options?: CreateApiV2PreferencesOptions) => { const {baseUrl = "https://api.dotdigital.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/octet-stream") const url = `${baseUrl.replace(/\/+$/, '')}/v2/preferences${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 res.blob() };