export type CreateApiContactsArgs = {check_duplicate: boolean, body: {first_name: string, last_name: string, owner_id: number, company_id: number, title?: string | undefined, reports_to_id?: number | undefined, has_left_company?: boolean | undefined, emails?: Array | undefined, phones?: Array | undefined, address?: ({street?: string | undefined, city?: string | undefined, state?: string | undefined, postal_code?: string | undefined}) | undefined, country_code?: string | undefined, social_media_urls?: Array | undefined, is_hot?: boolean | undefined, notes?: string | undefined, custom_fields?: Array | undefined}}; export type CreateApiContactsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a contact * * POST /contacts */ export const createApiContacts = async (args: CreateApiContactsArgs, options?: CreateApiContactsOptions) => { const {baseUrl = "https://api.catsone.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.check_duplicate != null) query.append("check_duplicate", String(args.check_duplicate)) const url = `${baseUrl.replace(/\/+$/, '')}/contacts${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 };