Skip to main content

Actions

The ballerinax/hubspot.marketing.transactional package exposes the following clients:

ClientPurpose
ClientSend transactional emails and manage SMTP API tokens via the HubSpot Marketing API.

Client​

Send transactional emails and manage SMTP API tokens via the HubSpot Marketing API.

Configuration​

FieldTypeDefaultDescription
authhttp:BearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredOAuth 2.0 refresh token config, bearer token, or private app legacy API key.
httpVersionHttpVersionHTTP_2_0HTTP protocol version.
timeoutdecimal30Request timeout in seconds.
retryConfigRetryConfig()Retry configuration for failed requests.
secureSocketClientSecureSocket()SSL/TLS configuration.
proxyProxyConfig()Proxy server configuration.

Initializing the client​

import ballerinax/hubspot.marketing.transactional;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;

transactional:Client hubspotClient = check new ({
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://api.hubapi.com/oauth/v1/token"
}
});

Operations​

Transactional email​

Send a single transactional email

Asynchronously send a transactional email. The email content is based on a template created in HubSpot, identified by emailId.

Parameters:

NameTypeRequiredDescription
payloadPublicSingleSendRequestEggYesThe email send request containing the email ID, recipient, and optional custom properties.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: EmailSendStatusView|error

Sample code:

transactional:EmailSendStatusView response = check hubspotClient->post single\-email/send(
{
emailId: 12345,
message: {
to: "[email protected]",
'from: "[email protected]",
sendId: "unique-send-id-001"
},
customProperties: {
"propertyName": {"value": "propertyValue"}
}
}
);

Sample response:

{
"statusId": "abc123",
"status": "PENDING",
"requestedAt": "2026-03-17T10:00:00Z"
}

SMTP token management​

Query SMTP API tokens

Query SMTP API tokens by campaign name or email campaign ID. Returns a paginated list of tokens.

Parameters:

NameTypeRequiredDescription
campaignNamestring?NoFilter tokens by campaign name.
emailCampaignIdstring?NoFilter tokens by email campaign ID.
afterstring?NoPagination cursor for the next page of results.
limitint:Signed32?NoMaximum number of tokens to return.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: CollectionResponseSmtpApiTokenViewForwardPaging|error

Sample code:

transactional:CollectionResponseSmtpApiTokenViewForwardPaging response = check hubspotClient->get smtp\-tokens(
campaignName = "Welcome Campaign"
);

Sample response:

{
"results": [
{
"id": "token-001",
"campaignName": "Welcome Campaign",
"emailCampaignId": "camp-123",
"createdBy": "[email protected]",
"createContact": true,
"createdAt": "2026-01-15T08:30:00Z"
}
]
}
Create a SMTP API token

Create a new SMTP API token for sending transactional emails via SMTP.

Parameters:

NameTypeRequiredDescription
payloadSmtpApiTokenRequestEggYesToken creation request with campaign name and contact creation preference.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: SmtpApiTokenView|error

Sample code:

transactional:SmtpApiTokenView response = check hubspotClient->post smtp\-tokens(
{
campaignName: "Order Confirmation",
createContact: true
}
);

Sample response:

{
"id": "token-002",
"campaignName": "Order Confirmation",
"emailCampaignId": "camp-456",
"createdBy": "[email protected]",
"createContact": true,
"createdAt": "2026-03-17T10:00:00Z",
"password": "generated-smtp-password"
}
Query a single token by ID

Retrieve a single SMTP API token by its token ID.

Parameters:

NameTypeRequiredDescription
tokenIdstringYesThe ID of the SMTP token to retrieve.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: SmtpApiTokenView|error

Sample code:

transactional:SmtpApiTokenView response = check hubspotClient->get smtp\-tokens/["token-001"];

Sample response:

{
"id": "token-001",
"campaignName": "Welcome Campaign",
"emailCampaignId": "camp-123",
"createdBy": "[email protected]",
"createContact": true,
"createdAt": "2026-01-15T08:30:00Z"
}
Reset the password of an existing token

Reset the password for an existing SMTP API token. The new password is returned in the response.

Parameters:

NameTypeRequiredDescription
tokenIdstringYesThe ID of the SMTP token whose password should be reset.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: SmtpApiTokenView|error

Sample code:

transactional:SmtpApiTokenView response = check hubspotClient->post smtp\-tokens/["token-001"]/password\-reset;

Sample response:

{
"id": "token-001",
"campaignName": "Welcome Campaign",
"emailCampaignId": "camp-123",
"createdBy": "[email protected]",
"createContact": true,
"createdAt": "2026-01-15T08:30:00Z",
"password": "new-generated-password"
}
Delete a single token by ID

Delete (archive) an existing SMTP API token by its token ID.

Parameters:

NameTypeRequiredDescription
tokenIdstringYesThe ID of the SMTP token to delete.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: error?

Sample code:

check hubspotClient->delete smtp\-tokens/["token-001"];