export type StopAppliesTo = 'contactOnly' | 'contactAndChildren'; export type StopStatus = 'contactOnStop' | 'creditLimitOnStop'; export type StopContactModel = {appliesTo?: StopAppliesTo | undefined, status?: StopStatus | undefined, stopReason?: string | undefined}; export type UpdateApiV1ContactsContactIdStopArgs = {'Customer-Id': number, contactId: number, body: StopContactModel}; export type UpdateApiV1ContactsContactIdStopOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Puts a contact on stop * * PUT /v1/contacts/{contactId}/stop */ export const updateApiV1ContactsContactIdStop = async (args: UpdateApiV1ContactsContactIdStopArgs, options?: UpdateApiV1ContactsContactIdStopOptions) => { const {baseUrl = "https://api.bigchange.com", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Customer-Id'] != null) headers.set("Customer-Id", String(args['Customer-Id'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/contacts/${encodeURIComponent(String(args.contactId))}/stop${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };