Skip to main content

Actions

The ballerinax/hubspot.automation.actions package exposes the following clients:

ClientPurpose
ClientManages HubSpot custom workflow extension definitions, functions, revisions, and callback completions.

Client

Manages HubSpot custom workflow extension definitions, functions, revisions, and callback completions.

Configuration

FieldTypeDefaultDescription
authhttp:BearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredAuthentication configuration. Use OAuth 2.0 or bearer token for callback endpoints, or ApiKeysConfig with a developer API key for definition/function/revision endpoints.
httpVersionHttpVersionHTTP_2_0HTTP protocol version.
timeoutdecimal30Request timeout in seconds.
retryConfigRetryConfig()Retry configuration for failed requests.
secureSocketClientSecureSocket()SSL/TLS configuration.
proxyProxyConfig()Proxy server configuration.
validationbooleantrueEnable or disable payload validation.

Initializing the client

import ballerinax/hubspot.automation.actions as hubspotAutomation;

configurable string apiKey = ?;

hubspotAutomation:Client hubspotClient = check new ({
auth: {
hapikey: apiKey,
privateAppLegacy: ""
}
});

Operations

Extension definitions

Get paged extension definitions

Retrieves a paginated list of extension definitions for the specified app.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
limitintNoMaximum number of results per page.
afterstringNoCursor token for the next page of results.
archivedbooleanNoWhether to include archived definitions. Defaults to false.

Returns: CollectionResponsePublicActionDefinitionForwardPaging|error

Sample code:

CollectionResponsePublicActionDefinitionForwardPaging response =
check hubspotClient->/[appId].get();

Sample response:

{
"results": [
{
"id": "12345",
"revisionId": "1",
"actionUrl": "https://example.com/action",
"published": true,
"labels": {
"actionName": "My Custom Action",
"actionDescription": "Performs a custom operation"
},
"inputFields": [],
"functions": [],
"objectTypes": ["CONTACT"]
}
],
"paging": {
"next": {
"after": "abc123"
}
}
}
Create a new extension definition

Creates a new custom workflow extension definition for the specified app.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
payloadPublicActionDefinitionEggYesThe extension definition to create, including labels, input fields, functions, and object types.

Returns: PublicActionDefinition|error

Sample code:

hubspotAutomation:FieldTypeDefinition fieldType = {
name: "staticInput",
'type: "string",
fieldType: "text",
label: "Static Input",
description: "A simple text input",
options: [],
externalOptions: false
};

hubspotAutomation:InputFieldDefinition inputField = {
isRequired: true,
automationFieldType: "test_automation_field",
typeDefinition: fieldType,
supportedValueTypes: ["STATIC_VALUE"]
};

hubspotAutomation:PublicActionFunction actionFunction = {
functionSource: "exports.main = (event, callback) => { callback({ outputFields: {} }); }",
functionType: "PRE_ACTION_EXECUTION"
};

hubspotAutomation:PublicActionDefinitionEgg extensionDef = {
actionUrl: "https://example.com/action",
published: false,
objectTypes: ["CONTACT"],
labels: {},
inputFields: [inputField],
functions: [actionFunction]
};

hubspotAutomation:PublicActionDefinition result =
check hubspotClient->/[appId].post(extensionDef);

Sample response:

{
"id": "67890",
"revisionId": "1",
"actionUrl": "https://example.com/action",
"published": false,
"labels": {},
"inputFields": [
{
"isRequired": true,
"automationFieldType": "test_automation_field",
"typeDefinition": {
"name": "staticInput",
"type": "string",
"fieldType": "text",
"label": "Static Input",
"options": [],
"externalOptions": false
},
"supportedValueTypes": ["STATIC_VALUE"]
}
],
"functions": [
{
"functionType": "PRE_ACTION_EXECUTION",
"id": "func_001"
}
],
"objectTypes": ["CONTACT"]
}
Get extension definition by ID

Retrieves a single extension definition by its app ID and definition ID.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
archivedbooleanNoWhether to return archived definitions. Defaults to false.

Returns: PublicActionDefinition|error

Sample code:

hubspotAutomation:PublicActionDefinition definition =
check hubspotClient->/[appId]/[definitionId].get();

Sample response:

{
"id": "67890",
"revisionId": "1",
"actionUrl": "https://example.com/action",
"published": false,
"labels": {
"actionName": "My Custom Action"
},
"inputFields": [],
"functions": [],
"objectTypes": ["CONTACT"]
}
Patch an existing extension definition

Partially updates an existing extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
payloadPublicActionDefinitionPatchYesFields to update on the extension definition.

Returns: PublicActionDefinition|error

Sample code:

hubspotAutomation:PublicActionDefinition updated =
check hubspotClient->/[appId]/[definitionId].patch({
actionUrl: "https://example.com/updated-action",
labels: {
actionName: "Updated Action Name"
}
});

Sample response:

{
"id": "67890",
"revisionId": "2",
"actionUrl": "https://example.com/updated-action",
"published": false,
"labels": {
"actionName": "Updated Action Name"
},
"inputFields": [],
"functions": [],
"objectTypes": ["CONTACT"]
}
Archive an extension definition

Archives (soft-deletes) an extension definition by its app ID and definition ID.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.

Returns: error?

Sample code:

check hubspotClient->/[appId]/[definitionId].delete();

Custom functions

Get all functions for a definition

Retrieves all custom functions associated with an extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.

Returns: CollectionResponsePublicActionFunctionIdentifierNoPaging|error

Sample code:

CollectionResponsePublicActionFunctionIdentifierNoPaging functions =
check hubspotClient->/[appId]/[definitionId]/functions.get();

Sample response:

{
"results": [
{
"functionType": "PRE_ACTION_EXECUTION",
"id": "func_001"
},
{
"functionType": "POST_ACTION_EXECUTION",
"id": "func_002"
}
]
}
Get function by type

Retrieves a function by its type for the specified extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type to retrieve.

Returns: PublicActionFunction|error

Sample code:

hubspotAutomation:PublicActionFunction fn =
check hubspotClient->/[appId]/[definitionId]/functions/["PRE_ACTION_EXECUTION"].get();

Sample response:

{
"functionSource": "exports.main = (event, callback) => { callback({ outputFields: {} }); }",
"functionType": "PRE_ACTION_EXECUTION",
"id": "func_001"
}
Insert or replace a function by type

Inserts a new function or replaces an existing one for the given type.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type to set.
payloadstringYesThe function source code as plain text.

Returns: PublicActionFunctionIdentifier|error

Sample code:

hubspotAutomation:PublicActionFunctionIdentifier result =
check hubspotClient->/[appId]/[definitionId]/functions/["PRE_ACTION_EXECUTION"]
.put("exports.main = (event, callback) => { callback({ outputFields: {} }); }");

Sample response:

{
"functionType": "PRE_ACTION_EXECUTION",
"id": "func_001"
}
Delete a function by type

Archives a function by its type for the specified extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type to delete.

Returns: error?

Sample code:

check hubspotClient->/[appId]/[definitionId]/functions/["PRE_ACTION_EXECUTION"].delete();
Get a specific function by type and ID

Retrieves a specific function by its type and unique function ID.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type.
functionIdstringYesThe unique function ID.

Returns: PublicActionFunction|error

Sample code:

hubspotAutomation:PublicActionFunction fn =
check hubspotClient->/[appId]/[definitionId]/functions/["PRE_ACTION_EXECUTION"]/[functionId].get();

Sample response:

{
"functionSource": "exports.main = (event, callback) => { callback({ outputFields: {} }); }",
"functionType": "PRE_ACTION_EXECUTION",
"id": "func_001"
}
Insert or replace a specific function by type and ID

Inserts a new function or replaces an existing one identified by type and function ID.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type.
functionIdstringYesThe unique function ID.
payloadstringYesThe function source code as plain text.

Returns: PublicActionFunctionIdentifier|error

Sample code:

hubspotAutomation:PublicActionFunctionIdentifier result =
check hubspotClient->/[appId]/[definitionId]/functions/["POST_ACTION_EXECUTION"]/[functionId]
.put("exports.main = (event, callback) => { callback({ outputFields: { status: 'done' } }); }");

Sample response:

{
"functionType": "POST_ACTION_EXECUTION",
"id": "func_003"
}
Delete a specific function by type and ID

Archives a specific function identified by its type and function ID.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
functionType"PRE_ACTION_EXECUTION"|"PRE_FETCH_OPTIONS"|"POST_FETCH_OPTIONS"|"POST_ACTION_EXECUTION"YesThe function type.
functionIdstringYesThe unique function ID.

Returns: error?

Sample code:

check hubspotClient->/[appId]/[definitionId]/functions/["POST_ACTION_EXECUTION"]/[functionId].delete();

Revisions

Get all revisions for a definition

Retrieves a paginated list of all revisions for an extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
limitintNoMaximum number of results per page.
afterstringNoCursor token for the next page of results.

Returns: CollectionResponsePublicActionRevisionForwardPaging|error

Sample code:

CollectionResponsePublicActionRevisionForwardPaging revisions =
check hubspotClient->/[appId]/[definitionId]/revisions.get();

Sample response:

{
"results": [
{
"revisionId": "2",
"createdAt": "2025-01-15T10:30:00Z",
"id": "rev_002",
"definition": {
"id": "67890",
"revisionId": "2",
"actionUrl": "https://example.com/updated-action",
"published": true,
"labels": {"actionName": "My Action"},
"inputFields": [],
"functions": [],
"objectTypes": ["CONTACT"]
}
}
],
"paging": {}
}
Get a specific revision by ID

Retrieves a specific revision of an extension definition.

Parameters:

NameTypeRequiredDescription
appIdint:Signed32YesThe HubSpot app ID.
definitionIdstringYesThe extension definition ID.
revisionIdstringYesThe revision ID.

Returns: PublicActionRevision|error

Sample code:

hubspotAutomation:PublicActionRevision revision =
check hubspotClient->/[appId]/[definitionId]/revisions/[revisionId].get();

Sample response:

{
"revisionId": "1",
"createdAt": "2025-01-10T08:00:00Z",
"id": "rev_001",
"definition": {
"id": "67890",
"revisionId": "1",
"actionUrl": "https://example.com/action",
"published": false,
"labels": {"actionName": "My Action"},
"inputFields": [],
"functions": [],
"objectTypes": ["CONTACT"]
}
}

Callbacks

Complete a single callback

Completes a single workflow callback, returning output fields to the HubSpot workflow.

Parameters:

NameTypeRequiredDescription
callbackIdstringYesThe callback ID provided by HubSpot when the workflow action is triggered.
payloadCallbackCompletionRequestYesThe completion request containing output field values.

Returns: error?

Sample code:

check hubspotClient->/callbacks/[callbackId]/complete.post({
outputFields: {
"status": "completed",
"result": "success"
}
});
Complete a batch of callbacks

Completes multiple workflow callbacks in a single batch request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputCallbackCompletionBatchRequestYesBatch request containing an array of callback completion entries, each with a callbackId and outputFields.

Returns: error?

Sample code:

hubspotAutomation:BatchInputCallbackCompletionBatchRequest batchRequest = {
inputs: [
{
callbackId: "callback_001",
outputFields: {"status": "completed"}
},
{
callbackId: "callback_002",
outputFields: {"status": "completed"}
}
]
};

check hubspotClient->/callbacks/complete.post(batchRequest);