import {z} from 'zod' export type CrmFilter = {highValue?: string | undefined, operator: 'BETWEEN' | 'CONTAINS_TOKEN' | 'EQ' | 'GT' | 'GTE' | 'HAS_PROPERTY' | 'IN' | 'LT' | 'LTE' | 'NEQ' | 'NOT_CONTAINS_TOKEN' | 'NOT_HAS_PROPERTY' | 'NOT_IN', propertyName: string, value?: string | undefined, values?: Array | undefined}; export type CrmFilterGroup = {filters: Array}; export type CrmExportsPublicCrmSearchRequest = {filterGroups: Array, filters: Array, query?: string | undefined, sorts: Array}; export type CrmExportsPublicExportViewRequest = {associatedObjectType: Array, exportInternalValuesOptions: Array<'NAMES' | 'VALUES'>, exportName: string, exportType: 'VIEW', format: 'CSV' | 'XLS' | 'XLSX', includeLabeledAssociations: boolean, includePrimaryDisplayPropertyForAssociatedObjects: boolean, language: 'AF_ZA' | 'AR_EG' | 'BG' | 'BN' | 'CA_ES' | 'CS' | 'DA_DK' | 'DE' | 'EL_GR' | 'EN' | 'EN_GB' | 'ES' | 'ES_MX' | 'ET_EE' | 'FI' | 'FR' | 'FR_CA' | 'HE_IL' | 'HI_IN' | 'HR' | 'HU' | 'ID' | 'IT' | 'JA' | 'KO_KR' | 'LT_LT' | 'MS' | 'NL' | 'NO' | 'PL' | 'PT_BR' | 'PT_PT' | 'RO' | 'RU' | 'SK_SK' | 'SL' | 'SV' | 'TH' | 'TL' | 'TR' | 'UK' | 'VI_VN' | 'ZH_CN' | 'ZH_HK' | 'ZH_TW', objectProperties: Array, objectType: string, overrideAssociatedObjectsPerDefinitionPerRowLimit: boolean, publicCrmSearchRequest?: CrmExportsPublicCrmSearchRequest | undefined}; export type CrmExportsPublicExportListRequest = {associatedObjectType: Array, exportInternalValuesOptions: Array<'NAMES' | 'VALUES'>, exportName: string, exportType: 'LIST', format: 'CSV' | 'XLS' | 'XLSX', includeLabeledAssociations: boolean, includePrimaryDisplayPropertyForAssociatedObjects: boolean, language: 'AF_ZA' | 'AR_EG' | 'BG' | 'BN' | 'CA_ES' | 'CS' | 'DA_DK' | 'DE' | 'EL_GR' | 'EN' | 'EN_GB' | 'ES' | 'ES_MX' | 'ET_EE' | 'FI' | 'FR' | 'FR_CA' | 'HE_IL' | 'HI_IN' | 'HR' | 'HU' | 'ID' | 'IT' | 'JA' | 'KO_KR' | 'LT_LT' | 'MS' | 'NL' | 'NO' | 'PL' | 'PT_BR' | 'PT_PT' | 'RO' | 'RU' | 'SK_SK' | 'SL' | 'SV' | 'TH' | 'TL' | 'TR' | 'UK' | 'VI_VN' | 'ZH_CN' | 'ZH_HK' | 'ZH_TW', listId: string, objectProperties: Array, objectType: string, overrideAssociatedObjectsPerDefinitionPerRowLimit: boolean}; export type CrmExportsPublicExportRequest = CrmExportsPublicExportViewRequest | CrmExportsPublicExportListRequest; export type CreateApiCrmExports202603ExportAsyncArgs = {body: CrmExportsPublicExportRequest}; export type CreateApiCrmExports202603ExportAsyncOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const taskLocator = z.object({id: z.string(), links: z.record(z.string(), z.string()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Start an export * * POST /crm/exports/2026-03/export/async * * Also accepts auth: developer_hapikey */ export const createApiCrmExports202603ExportAsync = async (args: CreateApiCrmExports202603ExportAsyncArgs, options?: CreateApiCrmExports202603ExportAsyncOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, privateApps} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (privateApps !== undefined) headers.set('authorization', `Bearer ${privateApps}`) const url = `${baseUrl.replace(/\/+$/, '')}/crm/exports/2026-03/export/async${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 validateResponse(taskLocator, await res.json()) };