import {z} from 'zod' export type AutomationActionsPublicExecutionTranslationRule = {conditions: {[key: string]: Record}, labelName: string}; export type AutomationActionsPublicActionFunction = {functionSource: string, functionType: 'POST_ACTION_EXECUTION' | 'POST_FETCH_OPTIONS' | 'PRE_ACTION_EXECUTION' | 'PRE_FETCH_OPTIONS', id?: string | undefined}; export type AutomationActionsPublicSingleFieldDependency = {controllingFieldName: string, dependencyType: 'SINGLE_FIELD', dependentFieldNames: Array}; export type AutomationActionsPublicConditionalSingleFieldDependency = {controllingFieldName: string, controllingFieldValue: string, dependencyType: 'CONDITIONAL_SINGLE_FIELD', dependentFieldNames: Array}; export type AutomationActionsPublicOption = {description?: string | undefined, displayOrder?: number | undefined, label: string, value: string}; export type AutomationActionsPublicFieldTypeDefinition = {description?: string | undefined, fieldType?: ('booleancheckbox' | 'calculation_equation' | 'checkbox' | 'date' | 'file' | 'html' | 'number' | 'phonenumber' | 'radio' | 'select' | 'text' | 'textarea') | undefined, helpText?: string | undefined, label?: string | undefined, name: string, options: Array, optionsUrl?: string | undefined, referencedObjectType?: 'OWNER' | undefined, type: 'bool' | 'date' | 'datetime' | 'enumeration' | 'json' | 'number' | 'object_coordinates' | 'phone_number' | 'string'}; export type AutomationActionsPublicInputFieldDefinition = {isRequired: boolean, supportedValueTypes?: (Array<'STATIC_VALUE' | 'OBJECT_PROPERTY'>) | undefined, typeDefinition: AutomationActionsPublicFieldTypeDefinition}; export type AutomationActionsPublicActionLabels = {actionCardContent?: string | undefined, actionDescription?: string | undefined, actionName: string, appDisplayName?: string | undefined, executionRules?: {[key: string]: string} | undefined, inputFieldDescriptions?: {[key: string]: string} | undefined, inputFieldLabels?: {[key: string]: string} | undefined, inputFieldOptionLabels?: {[key: string]: {[key: string]: string}} | undefined, outputFieldLabels?: {[key: string]: string} | undefined}; export type AutomationActionsPublicObjectRequestOptions = {properties: Array}; export type AutomationActionsOption = {description: string, displayOrder: number, doubleData: number, hidden: boolean, label: string, readOnly: boolean, value: string}; export type AutomationActionsIntegerFieldSchema = {maximum?: number | undefined, minimum?: number | undefined, type: 'INTEGER'}; export type AutomationActionsLongFieldSchema = {maximum?: number | undefined, minimum?: number | undefined, type: 'LONG'}; export type AutomationActionsDoubleFieldSchema = {maximum?: number | undefined, minimum?: number | undefined, type: 'DOUBLE'}; export type AutomationActionsStringFieldSchema = {format?: ('DATE' | 'DATE_TIME' | 'OBJECT_COORDINATE' | 'TIME' | 'URI') | undefined, type: 'STRING'}; export type AutomationActionsBooleanFieldSchema = {type: 'BOOLEAN'}; export type AutomationActionsArrayFieldSchema = {items: Record, type: 'ARRAY'}; export type AutomationActionsObjectFieldSchema = {properties: Record, type: 'OBJECT'}; export type AutomationActionsFieldTypeDefinition = {description?: string | undefined, externalOptions: boolean, externalOptionsReferenceType?: string | undefined, fieldType?: ('booleancheckbox' | 'calculation_equation' | 'calculation_read_time' | 'calculation_rollup' | 'calculation_score' | 'checkbox' | 'date' | 'file' | 'html' | 'number' | 'phonenumber' | 'radio' | 'select' | 'text' | 'textarea' | 'unknown') | undefined, helpText?: string | undefined, label?: string | undefined, name: string, options: Array, optionsUrl?: string | undefined, referencedObjectType?: ('ABANDONED_CART' | 'ACCEPTANCE_TEST' | 'AD' | 'AD_ACCOUNT' | 'AD_CAMPAIGN' | 'AD_GROUP' | 'AI_FORECAST' | 'ALL_PAGES' | 'APPROVAL' | 'APPROVAL_STEP' | 'ATTRIBUTION' | 'AUDIENCE' | 'AUTOMATION_JOURNEY' | 'AUTOMATION_PLATFORM_FLOW' | 'AUTOMATION_PLATFORM_FLOW_ACTION' | 'BET_ALERT' | 'BET_DELIVERABLE_SERVICE' | 'BLOG_LISTING_PAGE' | 'BLOG_POST' | 'CALL' | 'CAMPAIGN' | 'CAMPAIGN_BUDGET_ITEM' | 'CAMPAIGN_SPEND_ITEM' | 'CAMPAIGN_STEP' | 'CAMPAIGN_TEMPLATE' | 'CAMPAIGN_TEMPLATE_STEP' | 'CART' | 'CASE_STUDY' | 'CHATFLOW' | 'CLIP' | 'CMS_URL' | 'COMBO_EVENT_CONFIGURATION' | 'COMMERCE_PAYMENT' | 'COMMUNICATION' | 'COMPANY' | 'CONTACT' | 'CONTACT_CREATE_ATTRIBUTION' | 'CONTENT' | 'CONTENT_AUDIT' | 'CONTENT_AUDIT_PAGE' | 'CONVERSATION' | 'CONVERSATION_INBOX' | 'CONVERSATION_SESSION' | 'CRM_OBJECTS_DUMMY_TYPE' | 'CRM_PIPELINES_DUMMY_TYPE' | 'CTA' | 'CTA_VARIANT' | 'DATA_PRIVACY_CONSENT' | 'DATA_SYNC_STATE' | 'DEAL' | 'DEAL_CREATE_ATTRIBUTION' | 'DEAL_REGISTRATION' | 'DEAL_SPLIT' | 'DISCOUNT' | 'DISCOUNT_CODE' | 'DISCOUNT_TEMPLATE' | 'EMAIL' | 'ENGAGEMENT' | 'EXPORT' | 'EXTERNAL_WEB_URL' | 'FEE' | 'FEEDBACK_SUBMISSION' | 'FEEDBACK_SURVEY' | 'FILE_MANAGER_FILE' | 'FILE_MANAGER_FOLDER' | 'FOLDER' | 'FORECAST' | 'FORM' | 'FORM_SUBMISSION_INBOUNDDB' | 'GOAL_TARGET' | 'GOAL_TARGET_GROUP' | 'GOAL_TEMPLATE' | 'GSC_PROPERTY' | 'HUB' | 'IMPORT' | 'INVOICE' | 'KEYWORD' | 'KNOWLEDGE_ARTICLE' | 'LANDING_PAGE' | 'LEAD' | 'LINE_ITEM' | 'MARKETING_CALENDAR' | 'MARKETING_CAMPAIGN_UTM' | 'MARKETING_EMAIL' | 'MARKETING_EVENT' | 'MARKETING_EVENT_ATTENDANCE' | 'MARKETING_SMS' | 'MEDIA_BRIDGE' | 'MEETING_EVENT' | 'MIC' | 'NOTE' | 'OBJECT_LIST' | 'ORDER' | 'OWNER' | 'PARTNER_ACCOUNT' | 'PARTNER_CLIENT' | 'PARTNER_CLIENT_REVENUE' | 'PARTNER_SERVICE' | 'PAYMENT_LINK' | 'PAYMENT_SCHEDULE' | 'PAYMENT_SCHEDULE_INSTALLMENT' | 'PERMISSIONS_TESTING' | 'PLAYBOOK' | 'PLAYBOOK_QUESTION' | 'PLAYBOOK_SUBMISSION' | 'PLAYBOOK_SUBMISSION_ANSWER' | 'PLAYLIST' | 'PLAYLIST_FOLDER' | 'PODCAST_EPISODE' | 'PORTAL' | 'PORTAL_OBJECT_SYNC_MESSAGE' | 'POSTAL_MAIL' | 'PRIVACY_SCANNER_COOKIE' | 'PRODUCT' | 'PRODUCT_OR_FOLDER' | 'PROPERTY_INFO' | 'PROSPECTING_AGENT_CONTACT_ASSIGNMENT' | 'PUBLISHING_TASK' | 'QUARANTINED_SUBMISSION' | 'QUOTA' | 'QUOTE' | 'QUOTE_FIELD' | 'QUOTE_MODULE' | 'QUOTE_MODULE_FIELD' | 'QUOTE_TEMPLATE' | 'RESTORABLE_CRM_OBJECT' | 'ROSTER' | 'ROSTER_MEMBER' | 'SALES_DOCUMENT' | 'SALES_TASK' | 'SALES_WORKLOAD' | 'SALESFORCE_SYNC_ERROR' | 'SCHEDULING_PAGE' | 'SCHEMAS_BACKEND_TEST' | 'SCORE_CONFIGURATION' | 'SEQUENCE' | 'SEQUENCE_ENROLLMENT' | 'SEQUENCE_STEP' | 'SEQUENCE_STEP_ENROLLMENT' | 'SERVICE' | 'SITE_PAGE' | 'SNIPPET' | 'SOCIAL_BROADCAST' | 'SOCIAL_CHANNEL' | 'SOCIAL_POST' | 'SOCIAL_PROFILE' | 'SOX_PROTECTED_DUMMY_TYPE' | 'SOX_PROTECTED_TEST_TYPE' | 'SUBMISSION_TAG' | 'SUBSCRIPTION' | 'TASK' | 'TASK_TEMPLATE' | 'TAX' | 'TEMPLATE' | 'TICKET' | 'UNKNOWN' | 'UNSUBSCRIBE' | 'USER' | 'VIEW' | 'VIEW_BLOCK' | 'WEB_INTERACTIVE') | undefined, schema: AutomationActionsIntegerFieldSchema | AutomationActionsLongFieldSchema | AutomationActionsDoubleFieldSchema | AutomationActionsStringFieldSchema | AutomationActionsBooleanFieldSchema | AutomationActionsArrayFieldSchema | AutomationActionsObjectFieldSchema, type: 'bool' | 'currency_number' | 'date' | 'datetime' | 'enumeration' | 'json' | 'number' | 'object_coordinates' | 'phone_number' | 'string', useChirp: boolean}; export type AutomationActionsOutputFieldDefinition = {typeDefinition: AutomationActionsFieldTypeDefinition}; export type AutomationActionsPublicActionDefinitionEgg = {actionUrl: string, archivedAt?: number | undefined, executionRules?: Array | undefined, functions: Array, inputFieldDependencies?: (Array) | undefined, inputFields: Array, labels: {[key: string]: AutomationActionsPublicActionLabels}, objectRequestOptions?: AutomationActionsPublicObjectRequestOptions | undefined, objectTypes: Array, outputFields?: Array | undefined, published: boolean}; export type CreateApiAutomationActions202603AppIdArgs = {appId: number, body: AutomationActionsPublicActionDefinitionEgg}; export type CreateApiAutomationActions202603AppIdOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const automationActionsPublicExecutionTranslationRule = z.object({conditions: z.record(z.string(), z.object({})), labelName: z.string()}); export const automationActionsPublicActionFunctionIdentifier = z.object({functionType: z.enum(["POST_ACTION_EXECUTION", "POST_FETCH_OPTIONS", "PRE_ACTION_EXECUTION", "PRE_FETCH_OPTIONS"]), id: z.string().optional()}); export const automationActionsPublicSingleFieldDependency = z.object({controllingFieldName: z.string(), dependencyType: z.literal("SINGLE_FIELD"), dependentFieldNames: z.array(z.string())}); export const automationActionsPublicConditionalSingleFieldDependency = z.object({controllingFieldName: z.string(), controllingFieldValue: z.string(), dependencyType: z.literal("CONDITIONAL_SINGLE_FIELD"), dependentFieldNames: z.array(z.string())}); export const automationActionsPublicOption = z.object({description: z.string().optional(), displayOrder: z.number().int().optional(), label: z.string(), value: z.string()}); export const automationActionsPublicFieldTypeDefinition = z.object({description: z.string().optional(), fieldType: z.enum(["booleancheckbox", "calculation_equation", "checkbox", "date", "file", "html", "number", "phonenumber", "radio", "select", "text", "textarea"]).optional(), helpText: z.string().optional(), label: z.string().optional(), name: z.string(), options: z.array(automationActionsPublicOption), optionsUrl: z.string().optional(), referencedObjectType: z.literal("OWNER").optional(), type: z.enum(["bool", "date", "datetime", "enumeration", "json", "number", "object_coordinates", "phone_number", "string"])}); export const automationActionsPublicInputFieldDefinition = z.object({isRequired: z.boolean(), supportedValueTypes: z.array(z.enum(["STATIC_VALUE", "OBJECT_PROPERTY"])).optional(), typeDefinition: automationActionsPublicFieldTypeDefinition}); export const automationActionsPublicActionLabels = z.object({actionCardContent: z.string().optional(), actionDescription: z.string().optional(), actionName: z.string(), appDisplayName: z.string().optional(), executionRules: z.record(z.string(), z.string()).optional(), inputFieldDescriptions: z.record(z.string(), z.string()).optional(), inputFieldLabels: z.record(z.string(), z.string()).optional(), inputFieldOptionLabels: z.record(z.string(), z.record(z.string(), z.string())).optional(), outputFieldLabels: z.record(z.string(), z.string()).optional()}); export const automationActionsPublicObjectRequestOptions = z.object({properties: z.array(z.string())}); export const automationActionsOption = z.object({description: z.string(), displayOrder: z.number().int(), doubleData: z.number(), hidden: z.boolean(), label: z.string(), readOnly: z.boolean(), value: z.string()}); export const automationActionsIntegerFieldSchema = z.object({maximum: z.number().int().optional(), minimum: z.number().int().optional(), type: z.literal("INTEGER")}); export const automationActionsLongFieldSchema = z.object({maximum: z.number().int().optional(), minimum: z.number().int().optional(), type: z.literal("LONG")}); export const automationActionsDoubleFieldSchema = z.object({maximum: z.number().optional(), minimum: z.number().optional(), type: z.literal("DOUBLE")}); export const automationActionsStringFieldSchema = z.object({format: z.enum(["DATE", "DATE_TIME", "OBJECT_COORDINATE", "TIME", "URI"]).optional(), type: z.literal("STRING")}); export const automationActionsBooleanFieldSchema = z.object({type: z.literal("BOOLEAN")}); export const automationActionsArrayFieldSchema = z.object({items: z.object({}), type: z.literal("ARRAY")}); export const automationActionsObjectFieldSchema = z.object({properties: z.object({}), type: z.literal("OBJECT")}); export const automationActionsFieldTypeDefinition = z.object({description: z.string().optional(), externalOptions: z.boolean(), externalOptionsReferenceType: z.string().optional(), fieldType: z.enum(["booleancheckbox", "calculation_equation", "calculation_read_time", "calculation_rollup", "calculation_score", "checkbox", "date", "file", "html", "number", "phonenumber", "radio", "select", "text", "textarea", "unknown"]).optional(), helpText: z.string().optional(), label: z.string().optional(), name: z.string(), options: z.array(automationActionsOption), optionsUrl: z.string().optional(), referencedObjectType: z.enum(["ABANDONED_CART", "ACCEPTANCE_TEST", "AD", "AD_ACCOUNT", "AD_CAMPAIGN", "AD_GROUP", "AI_FORECAST", "ALL_PAGES", "APPROVAL", "APPROVAL_STEP", "ATTRIBUTION", "AUDIENCE", "AUTOMATION_JOURNEY", "AUTOMATION_PLATFORM_FLOW", "AUTOMATION_PLATFORM_FLOW_ACTION", "BET_ALERT", "BET_DELIVERABLE_SERVICE", "BLOG_LISTING_PAGE", "BLOG_POST", "CALL", "CAMPAIGN", "CAMPAIGN_BUDGET_ITEM", "CAMPAIGN_SPEND_ITEM", "CAMPAIGN_STEP", "CAMPAIGN_TEMPLATE", "CAMPAIGN_TEMPLATE_STEP", "CART", "CASE_STUDY", "CHATFLOW", "CLIP", "CMS_URL", "COMBO_EVENT_CONFIGURATION", "COMMERCE_PAYMENT", "COMMUNICATION", "COMPANY", "CONTACT", "CONTACT_CREATE_ATTRIBUTION", "CONTENT", "CONTENT_AUDIT", "CONTENT_AUDIT_PAGE", "CONVERSATION", "CONVERSATION_INBOX", "CONVERSATION_SESSION", "CRM_OBJECTS_DUMMY_TYPE", "CRM_PIPELINES_DUMMY_TYPE", "CTA", "CTA_VARIANT", "DATA_PRIVACY_CONSENT", "DATA_SYNC_STATE", "DEAL", "DEAL_CREATE_ATTRIBUTION", "DEAL_REGISTRATION", "DEAL_SPLIT", "DISCOUNT", "DISCOUNT_CODE", "DISCOUNT_TEMPLATE", "EMAIL", "ENGAGEMENT", "EXPORT", "EXTERNAL_WEB_URL", "FEE", "FEEDBACK_SUBMISSION", "FEEDBACK_SURVEY", "FILE_MANAGER_FILE", "FILE_MANAGER_FOLDER", "FOLDER", "FORECAST", "FORM", "FORM_SUBMISSION_INBOUNDDB", "GOAL_TARGET", "GOAL_TARGET_GROUP", "GOAL_TEMPLATE", "GSC_PROPERTY", "HUB", "IMPORT", "INVOICE", "KEYWORD", "KNOWLEDGE_ARTICLE", "LANDING_PAGE", "LEAD", "LINE_ITEM", "MARKETING_CALENDAR", "MARKETING_CAMPAIGN_UTM", "MARKETING_EMAIL", "MARKETING_EVENT", "MARKETING_EVENT_ATTENDANCE", "MARKETING_SMS", "MEDIA_BRIDGE", "MEETING_EVENT", "MIC", "NOTE", "OBJECT_LIST", "ORDER", "OWNER", "PARTNER_ACCOUNT", "PARTNER_CLIENT", "PARTNER_CLIENT_REVENUE", "PARTNER_SERVICE", "PAYMENT_LINK", "PAYMENT_SCHEDULE", "PAYMENT_SCHEDULE_INSTALLMENT", "PERMISSIONS_TESTING", "PLAYBOOK", "PLAYBOOK_QUESTION", "PLAYBOOK_SUBMISSION", "PLAYBOOK_SUBMISSION_ANSWER", "PLAYLIST", "PLAYLIST_FOLDER", "PODCAST_EPISODE", "PORTAL", "PORTAL_OBJECT_SYNC_MESSAGE", "POSTAL_MAIL", "PRIVACY_SCANNER_COOKIE", "PRODUCT", "PRODUCT_OR_FOLDER", "PROPERTY_INFO", "PROSPECTING_AGENT_CONTACT_ASSIGNMENT", "PUBLISHING_TASK", "QUARANTINED_SUBMISSION", "QUOTA", "QUOTE", "QUOTE_FIELD", "QUOTE_MODULE", "QUOTE_MODULE_FIELD", "QUOTE_TEMPLATE", "RESTORABLE_CRM_OBJECT", "ROSTER", "ROSTER_MEMBER", "SALES_DOCUMENT", "SALES_TASK", "SALES_WORKLOAD", "SALESFORCE_SYNC_ERROR", "SCHEDULING_PAGE", "SCHEMAS_BACKEND_TEST", "SCORE_CONFIGURATION", "SEQUENCE", "SEQUENCE_ENROLLMENT", "SEQUENCE_STEP", "SEQUENCE_STEP_ENROLLMENT", "SERVICE", "SITE_PAGE", "SNIPPET", "SOCIAL_BROADCAST", "SOCIAL_CHANNEL", "SOCIAL_POST", "SOCIAL_PROFILE", "SOX_PROTECTED_DUMMY_TYPE", "SOX_PROTECTED_TEST_TYPE", "SUBMISSION_TAG", "SUBSCRIPTION", "TASK", "TASK_TEMPLATE", "TAX", "TEMPLATE", "TICKET", "UNKNOWN", "UNSUBSCRIBE", "USER", "VIEW", "VIEW_BLOCK", "WEB_INTERACTIVE"]).optional(), schema: z.union([automationActionsIntegerFieldSchema, automationActionsLongFieldSchema, automationActionsDoubleFieldSchema, automationActionsStringFieldSchema, automationActionsBooleanFieldSchema, automationActionsArrayFieldSchema, automationActionsObjectFieldSchema]), type: z.enum(["bool", "currency_number", "date", "datetime", "enumeration", "json", "number", "object_coordinates", "phone_number", "string"]), useChirp: z.boolean()}); export const automationActionsOutputFieldDefinition = z.object({typeDefinition: automationActionsFieldTypeDefinition}); export const automationActionsPublicActionDefinition = z.object({actionUrl: z.string(), archivedAt: z.number().int().optional(), executionRules: z.array(automationActionsPublicExecutionTranslationRule).optional(), functions: z.array(automationActionsPublicActionFunctionIdentifier), id: z.string(), inputFieldDependencies: z.array(z.union([automationActionsPublicSingleFieldDependency, automationActionsPublicConditionalSingleFieldDependency])).optional(), inputFields: z.array(automationActionsPublicInputFieldDefinition), labels: z.record(z.string(), automationActionsPublicActionLabels), objectRequestOptions: automationActionsPublicObjectRequestOptions.optional(), objectTypes: z.array(z.string()), outputFields: z.array(automationActionsOutputFieldDefinition).optional(), published: z.boolean(), revisionId: z.string()}); 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 }; /** * Create a new custom action definition * * POST /automation/actions/2026-03/{appId} * * Also accepts auth: developer_hapikey */ export const createApiAutomationActions202603AppId = async (args: CreateApiAutomationActions202603AppIdArgs, options?: CreateApiAutomationActions202603AppIdOptions) => { 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(/\/+$/, '')}/automation/actions/2026-03/${encodeURIComponent(String(args.appId))}${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(automationActionsPublicActionDefinition, await res.json()) };