Skip to main content

Actions

The ballerinax/hubspot.crm.engagements.communications package exposes the following clients:

ClientPurpose
ClientManage HubSpot communication records: CRUD, batch operations, and search.

Client

Manage HubSpot communication records: CRUD, batch operations, and search.

Configuration

FieldTypeDefaultDescription
authhttp:BearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredAuthentication configuration: OAuth 2.0 refresh token, bearer token, or API keys.
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.crm.engagements.communications;

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

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

Operations

Single record operations

Create a communication

Signature: post /

Creates a new communication record with the specified properties and optional associations.

Parameters:

NameTypeRequiredDescription
payloadSimplePublicObjectInputForCreateYesThe communication properties and associations.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: SimplePublicObject|error

Sample code:

communications:SimplePublicObject response = check communicationsClient->/.post({
properties: {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_logged_from": "CRM",
"hs_communication_body": "Hello! This is a WhatsApp message."
},
associations: [
{
types: [
{
associationCategory: "HUBSPOT_DEFINED",
associationTypeId: 81
}
],
to: {
id: "12345"
}
}
]
});

Sample response:

{
"id": "67890",
"properties": {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_logged_from": "CRM",
"hs_communication_body": "Hello! This is a WhatsApp message.",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z",
"hs_object_id": "67890"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
Retrieve messages

Signature: get /

Retrieves a paginated list of communication records with optional property and association filtering.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoOptional HTTP headers.
queriesGetCrmV3ObjectsCommunicationsGetPageQueriesNoQuery parameters including limit, after, properties, associations, archived, and propertiesWithHistory.

Returns: CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error

Sample code:

communications:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response =
check communicationsClient->/.get(
queries = {
'limit: 10,
properties: ["hs_communication_channel_type", "hs_communication_body"]
}
);

Sample response:

{
"results": [
{
"id": "67890",
"properties": {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_body": "Hello! This is a WhatsApp message.",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z",
"hs_object_id": "67890"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": {
"next": {
"after": "67890",
"link": "https://api.hubapi.com/crm/v3/objects/communications?after=67890"
}
}
}
Retrieve a message

Signature: get /[string communicationId]

Retrieves a single communication record by its ID, with optional properties and associations.

Parameters:

NameTypeRequiredDescription
communicationIdstringYesThe ID of the communication record to retrieve.
headersmap<string|string[]>NoOptional HTTP headers.
queriesGetCrmV3ObjectsCommunicationsCommunicationIdGetByIdQueriesNoQuery parameters including properties, associations, archived, propertiesWithHistory, and idProperty.

Returns: SimplePublicObjectWithAssociations|error

Sample code:

communications:SimplePublicObjectWithAssociations response =
check communicationsClient->/["67890"].get(
queries = {
properties: ["hs_communication_channel_type", "hs_communication_body"]
}
);

Sample response:

{
"id": "67890",
"properties": {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_body": "Hello! This is a WhatsApp message.",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z",
"hs_object_id": "67890"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
Update a message

Signature: patch /[string communicationId]

Updates an existing communication record with new property values.

Parameters:

NameTypeRequiredDescription
communicationIdstringYesThe ID of the communication record to update.
payloadSimplePublicObjectInputYesThe properties to update.
headersmap<string|string[]>NoOptional HTTP headers.
queriesPatchCrmV3ObjectsCommunicationsCommunicationIdUpdateQueriesNoQuery parameters including idProperty.

Returns: SimplePublicObject|error

Sample code:

communications:SimplePublicObject response = check communicationsClient->/["67890"].patch({
properties: {
"hs_communication_body": "Updated message body content."
}
});

Sample response:

{
"id": "67890",
"properties": {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_body": "Updated message body content.",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T11:00:00.000Z",
"hs_object_id": "67890"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
}
Archive a message

Signature: delete /[string communicationId]

Archives (soft-deletes) a communication record by its ID.

Parameters:

NameTypeRequiredDescription
communicationIdstringYesThe ID of the communication record to archive.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: error?

Sample code:

check communicationsClient->/["67890"].delete();

Batch operations

Create a batch of messages

Signature: post /batch/create

Creates multiple communication records in a single batch request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectInputForCreateYesBatch input containing an array of communication records to create.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

communications:BatchResponseSimplePublicObject|communications:BatchResponseSimplePublicObjectWithErrors response =
check communicationsClient->/batch/create.post({
inputs: [
{
properties: {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_logged_from": "CRM",
"hs_communication_body": "First LinkedIn message"
},
associations: [
{
types: [{associationCategory: "HUBSPOT_DEFINED", associationTypeId: 81}],
to: {id: "12345"}
}
]
},
{
properties: {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_logged_from": "CRM",
"hs_communication_body": "Second LinkedIn message"
},
associations: [
{
types: [{associationCategory: "HUBSPOT_DEFINED", associationTypeId: 81}],
to: {id: "12346"}
}
]
}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "67891",
"properties": {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_body": "First LinkedIn message",
"hs_object_id": "67891"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
},
{
"id": "67892",
"properties": {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_body": "Second LinkedIn message",
"hs_object_id": "67892"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"startedAt": "2025-01-15T10:30:00.000Z",
"completedAt": "2025-01-15T10:30:01.000Z"
}
Retrieve a batch of messages

Signature: post /batch/read

Retrieves multiple communication records by their IDs in a single batch request.

Parameters:

NameTypeRequiredDescription
payloadBatchReadInputSimplePublicObjectIdYesBatch input containing record IDs, requested properties, and properties with history.
headersmap<string|string[]>NoOptional HTTP headers.
queriesPostCrmV3ObjectsCommunicationsBatchReadReadQueriesNoQuery parameters including archived.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

communications:BatchResponseSimplePublicObject|communications:BatchResponseSimplePublicObjectWithErrors response =
check communicationsClient->/batch/read.post({
properties: ["hs_communication_channel_type", "hs_communication_body"],
propertiesWithHistory: ["hs_communication_body"],
inputs: [
{id: "67891"},
{id: "67892"}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "67891",
"properties": {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_body": "First LinkedIn message",
"hs_object_id": "67891"
},
"propertiesWithHistory": {
"hs_communication_body": [
{
"value": "First LinkedIn message",
"timestamp": "2025-01-15T10:30:00.000Z",
"sourceType": "CRM_UI",
"sourceId": "userId:12345"
}
]
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"startedAt": "2025-01-15T10:30:00.000Z",
"completedAt": "2025-01-15T10:30:01.000Z"
}
Update a batch of messages

Signature: post /batch/update

Updates multiple communication records in a single batch request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputYesBatch input containing record IDs and properties to update.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

communications:BatchResponseSimplePublicObject|communications:BatchResponseSimplePublicObjectWithErrors response =
check communicationsClient->/batch/update.post({
inputs: [
{
id: "67891",
properties: {
"hs_communication_body": "Updated first message"
}
},
{
id: "67892",
properties: {
"hs_communication_body": "Updated second message"
}
}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "67891",
"properties": {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_body": "Updated first message",
"hs_object_id": "67891"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
},
{
"id": "67892",
"properties": {
"hs_communication_channel_type": "LINKEDIN_MESSAGE",
"hs_communication_body": "Updated second message",
"hs_object_id": "67892"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
}
],
"startedAt": "2025-01-15T11:00:00.000Z",
"completedAt": "2025-01-15T11:00:01.000Z"
}
Create and update a batch of messages

Signature: post /batch/upsert

Creates or updates multiple communication records in a single batch request based on a unique ID property.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputUpsertYesBatch input containing records to upsert with their ID property and properties.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors|error

Sample code:

communications:BatchResponseSimplePublicUpsertObject|communications:BatchResponseSimplePublicUpsertObjectWithErrors response =
check communicationsClient->/batch/upsert.post({
inputs: [
{
id: "67891",
idProperty: "hs_object_id",
properties: {
"hs_communication_body": "Upserted message content"
}
}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "67891",
"properties": {
"hs_communication_body": "Upserted message content",
"hs_object_id": "67891"
},
"new": false,
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:30:00.000Z",
"archived": false
}
],
"startedAt": "2025-01-15T11:30:00.000Z",
"completedAt": "2025-01-15T11:30:01.000Z"
}
Archive a batch of messages

Signature: post /batch/archive

Archives (soft-deletes) multiple communication records in a single batch request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectIdYesBatch input containing an array of record IDs to archive.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: error?

Sample code:

check communicationsClient->/batch/archive.post({
inputs: [
{id: "67891"},
{id: "67892"}
]
});
Search for messages

Signature: post /search

Searches for communication records using filters, query text, and sorting options.

Parameters:

NameTypeRequiredDescription
payloadPublicObjectSearchRequestYesSearch request with filters, query, sorting, properties, and pagination.
headersmap<string|string[]>NoOptional HTTP headers.

Returns: CollectionResponseWithTotalSimplePublicObjectForwardPaging|error

Sample code:

communications:CollectionResponseWithTotalSimplePublicObjectForwardPaging response =
check communicationsClient->/search.post({
filterGroups: [
{
filters: [
{
propertyName: "hs_communication_channel_type",
operator: "EQ",
value: "WHATS_APP"
}
]
}
],
properties: ["hs_communication_channel_type", "hs_communication_body"],
'limit: 10
});

Sample response:

{
"total": 1,
"results": [
{
"id": "67890",
"properties": {
"hs_communication_channel_type": "WHATS_APP",
"hs_communication_body": "Hello! This is a WhatsApp message.",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z",
"hs_object_id": "67890"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": {}
}