import {z} from 'zod' export type GetApiCrmObjects202603LeadsLeadsIdArgs = {leadsId: string, archived?: boolean | undefined, associations?: Array | undefined, idProperty?: string | undefined, properties?: Array | undefined, propertiesWithHistory?: Array | undefined}; export type GetApiCrmObjects202603LeadsLeadsIdOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const nextPage = z.object({after: z.string(), link: z.string().optional()}); export const previousPage = z.object({before: z.string(), link: z.string().optional()}); export const paging = z.object({next: nextPage.optional(), prev: previousPage.optional()}); export const crmObjectsAssociatedId = z.object({id: z.string(), type: z.string()}); export const crmObjectsCollectionResponseAssociatedId = z.object({paging: paging.optional(), results: z.array(crmObjectsAssociatedId)}); export const crmValueWithTimestamp = z.object({sourceId: z.string().optional(), sourceLabel: z.string().optional(), sourceType: z.string(), timestamp: z.string(), updatedByUserId: z.number().int().optional(), value: z.string()}); export const crmObjectsSimplePublicObjectWithAssociations = z.object({archived: z.boolean(), archivedAt: z.string().optional(), associations: z.record(z.string(), crmObjectsCollectionResponseAssociatedId).optional(), createdAt: z.string(), id: z.string(), objectWriteTraceId: z.string().optional(), properties: z.record(z.string(), z.string()), propertiesWithHistory: z.record(z.string(), z.array(crmValueWithTimestamp)).optional(), updatedAt: z.string(), url: 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 }; /** * Read * * GET /crm/objects/2026-03/leads/{leadsId} * * Also accepts auth: developer_hapikey */ export const getApiCrmObjects202603LeadsLeadsId = async (args: GetApiCrmObjects202603LeadsLeadsIdArgs, options?: GetApiCrmObjects202603LeadsLeadsIdOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, privateApps} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.archived != null) query.append("archived", String(args.archived)) for (const item of args.associations ?? []) query.append("associations", String(item)) if (args.idProperty != null) query.append("idProperty", String(args.idProperty)) for (const item of args.properties ?? []) query.append("properties", String(item)) for (const item of args.propertiesWithHistory ?? []) query.append("propertiesWithHistory", String(item)) if (privateApps !== undefined) headers.set('authorization', `Bearer ${privateApps}`) const url = `${baseUrl.replace(/\/+$/, '')}/crm/objects/2026-03/leads/${encodeURIComponent(String(args.leadsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(crmObjectsSimplePublicObjectWithAssociations, await res.json()) };