Skip to main content

Actions

The ballerinax/hubspot.crm.obj.contacts package exposes the following clients:

ClientPurpose
ClientProvides all HubSpot CRM Contacts API operations: CRUD, batch, search, merge, and GDPR deletion.

Client

Provides all HubSpot CRM Contacts API operations: CRUD, batch, search, merge, and GDPR deletion.

Configuration

FieldTypeDefaultDescription
authBearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredAuthentication configuration: bearer token, OAuth 2.0 refresh token, or private app API key.
httpVersionhttp:HttpVersionHTTP_2_0HTTP protocol version to use.
timeoutdecimal30Request timeout in seconds.
retryConfighttp:RetryConfig?()Retry configuration for failed requests.
secureSockethttp:ClientSecureSocket?()SSL/TLS configuration.
proxyhttp:ProxyConfig?()Proxy server configuration.
validationbooleantrueEnable constraint validation on response payloads.
laxDataBindingbooleantrueAllow lax data binding to ignore unknown fields in responses.

Initializing the client

import ballerinax/hubspot.crm.obj.contacts as hscontacts;

configurable string token = ?;

hscontacts:Client hubspotClient = check new ({
auth: {
token: token
}
});

Operations

Contact CRUD

List contacts

Enumerates all contacts with optional forward pagination, property selection, and association fetching.

Parameters:

NameTypeRequiredDescription
queriesGetCrmV3ObjectsContactsGetPageQueriesNoOptional query parameters including limit, after (pagination cursor), properties, propertiesWithHistory, associations, and archived.
headersmap<string|string[]>NoAdditional HTTP headers to include in the request.

Returns: CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error

Sample code:

hscontacts:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging contacts =
check hubspotClient->/( queries = {
'limit: 10,
properties: ["firstname", "lastname", "email"]
});

Sample response:

{
"results": [
{
"id": "101",
"properties": {
"firstname": "Alice",
"lastname": "Smith",
"email": "[email protected]",
"createdate": "2024-01-15T10:00:00.000Z",
"lastmodifieddate": "2024-06-01T08:30:00.000Z"
},
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-06-01T08:30:00.000Z",
"archived": false
}
],
"paging": {
"next": {
"after": "102",
"link": "https://api.hubapi.com/crm/v3/objects/contacts?after=102"
}
}
}
Create a contact

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

Parameters:

NameTypeRequiredDescription
payloadSimplePublicObjectInputForCreateYesContact creation payload containing properties map, optional associations, and optional objectWriteTraceId.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: SimplePublicObject|error

Sample code:

hscontacts:SimplePublicObject contact = check hubspotClient->/.post({
properties: {
"firstname": "Bob",
"lastname": "Johnson",
"email": "[email protected]",
"phone": "+1-555-0100",
"company": "Acme Corp"
},
associations: []
});

Sample response:

{
"id": "201",
"properties": {
"firstname": "Bob",
"lastname": "Johnson",
"email": "[email protected]",
"phone": "+1-555-0100",
"company": "Acme Corp",
"createdate": "2026-03-18T12:00:00.000Z",
"lastmodifieddate": "2026-03-18T12:00:00.000Z",
"hs_object_id": "201"
},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T12:00:00.000Z",
"archived": false
}
Get a contact by ID

Retrieves a single contact record by its HubSpot internal ID, with optional property and association fetching.

Parameters:

NameTypeRequiredDescription
contactIdstringYesThe HubSpot internal contact ID.
queriesGetCrmV3ObjectsContactsContactIdGetByIdQueriesNoOptional query parameters including properties, propertiesWithHistory, associations, and archived.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: SimplePublicObjectWithAssociations|error

Sample code:

hscontacts:SimplePublicObjectWithAssociations contact =
check hubspotClient->/["201"](queries = {
properties: ["firstname", "lastname", "email", "phone"]
});

Sample response:

{
"id": "201",
"properties": {
"firstname": "Bob",
"lastname": "Johnson",
"email": "[email protected]",
"phone": "+1-555-0100"
},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T12:00:00.000Z",
"archived": false,
"associations": {}
}
Update a contact

Updates properties of an existing contact. Only the fields provided in the payload are modified.

Parameters:

NameTypeRequiredDescription
contactIdstringYesThe HubSpot internal contact ID to update.
payloadSimplePublicObjectInputYesUpdate payload containing a properties map of field names to new values.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: SimplePublicObject|error

Sample code:

hscontacts:SimplePublicObject updated = check hubspotClient->/["201"].patch({
properties: {
"hs_lead_status": "IN_PROGRESS",
"phone": "+1-555-0199"
}
});

Sample response:

{
"id": "201",
"properties": {
"firstname": "Bob",
"lastname": "Johnson",
"email": "[email protected]",
"phone": "+1-555-0199",
"hs_lead_status": "IN_PROGRESS",
"lastmodifieddate": "2026-03-18T13:00:00.000Z"
},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T13:00:00.000Z",
"archived": false
}
Archive a contact

Archives (soft-deletes) a contact by its HubSpot ID. Archived contacts can be restored from the HubSpot UI.

Parameters:

NameTypeRequiredDescription
contactIdstringYesThe HubSpot internal contact ID to archive.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: error?

Sample code:

check hubspotClient->/["201"].delete();

Batch operations

Batch read contacts

Reads multiple contacts in a single request by internal IDs or a unique property value.

Parameters:

NameTypeRequiredDescription
payloadBatchReadInputSimplePublicObjectIdYesBatch read input containing inputs (list of IDs), properties, propertiesWithHistory, and optional idProperty to use an alternate unique identifier.
queriesPostCrmV3ObjectsContactsBatchReadReadQueriesNoOptional archived flag (default false).
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscontacts:BatchResponseSimplePublicObject|hscontacts:BatchResponseSimplePublicObjectWithErrors result =
check hubspotClient->/batch/read.post({
inputs: [
{id: "101"},
{id: "201"}
],
properties: ["firstname", "lastname", "email"]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "101",
"properties": {"firstname": "Alice", "lastname": "Smith", "email": "[email protected]"},
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-06-01T08:30:00.000Z",
"archived": false
},
{
"id": "201",
"properties": {"firstname": "Bob", "lastname": "Johnson", "email": "[email protected]"},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T13:00:00.000Z",
"archived": false
}
],
"startedAt": "2026-03-18T14:00:00.000Z",
"completedAt": "2026-03-18T14:00:00.050Z"
}
Batch create contacts

Creates multiple contact records in a single API call.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectInputForCreateYesBatch create input containing an inputs array of SimplePublicObjectInputForCreate objects, each with a properties map.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscontacts:BatchResponseSimplePublicObject|hscontacts:BatchResponseSimplePublicObjectWithErrors result =
check hubspotClient->/batch/create.post({
inputs: [
{
properties: {"firstname": "Carol", "lastname": "White", "email": "[email protected]"},
associations: []
},
{
properties: {"firstname": "Dave", "lastname": "Brown", "email": "[email protected]"},
associations: []
}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "301",
"properties": {"firstname": "Carol", "lastname": "White", "email": "[email protected]"},
"createdAt": "2026-03-18T14:01:00.000Z",
"updatedAt": "2026-03-18T14:01:00.000Z",
"archived": false
},
{
"id": "302",
"properties": {"firstname": "Dave", "lastname": "Brown", "email": "[email protected]"},
"createdAt": "2026-03-18T14:01:00.000Z",
"updatedAt": "2026-03-18T14:01:00.000Z",
"archived": false
}
],
"startedAt": "2026-03-18T14:01:00.000Z",
"completedAt": "2026-03-18T14:01:00.100Z"
}
Batch update contacts

Updates properties on multiple existing contacts in a single call.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputYesBatch update input with an inputs array; each item specifies an id, a properties map, and an optional idProperty for alternate key lookup.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscontacts:BatchResponseSimplePublicObject|hscontacts:BatchResponseSimplePublicObjectWithErrors result =
check hubspotClient->/batch/update.post({
inputs: [
{id: "101", properties: {"hs_email_optout": "true"}},
{id: "201", properties: {"hs_email_optout": "true"}}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "101",
"properties": {"hs_email_optout": "true", "lastmodifieddate": "2026-03-18T14:05:00.000Z"},
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2026-03-18T14:05:00.000Z",
"archived": false
},
{
"id": "201",
"properties": {"hs_email_optout": "true", "lastmodifieddate": "2026-03-18T14:05:00.000Z"},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T14:05:00.000Z",
"archived": false
}
],
"startedAt": "2026-03-18T14:05:00.000Z",
"completedAt": "2026-03-18T14:05:00.080Z"
}
Batch upsert contacts

Creates or updates multiple contacts based on a unique property identifier. Contacts matching the identifier are updated; others are created.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputUpsertYesUpsert input with an inputs array; each item has idProperty (the unique key property name), id (the key value), and a properties map.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors|error

Sample code:

hscontacts:BatchResponseSimplePublicUpsertObject|hscontacts:BatchResponseSimplePublicUpsertObjectWithErrors result =
check hubspotClient->/batch/upsert.post({
inputs: [
{
idProperty: "email",
id: "[email protected]",
properties: {"hs_lead_status": "NEW"}
},
{
idProperty: "email",
id: "[email protected]",
properties: {"firstname": "New", "lastname": "Person", "hs_lead_status": "NEW"}
}
]
});

Sample response:

{
"status": "COMPLETE",
"results": [
{
"id": "101",
"properties": {"hs_lead_status": "NEW"},
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2026-03-18T14:10:00.000Z",
"archived": false,
"new": false
},
{
"id": "401",
"properties": {"firstname": "New", "lastname": "Person", "hs_lead_status": "NEW"},
"createdAt": "2026-03-18T14:10:00.000Z",
"updatedAt": "2026-03-18T14:10:00.000Z",
"archived": false,
"new": true
}
],
"startedAt": "2026-03-18T14:10:00.000Z",
"completedAt": "2026-03-18T14:10:00.090Z"
}
Batch archive contacts

Archives multiple contacts by their internal IDs in a single call.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectIdYesBatch archive input with an inputs array of objects each containing an id field.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: error?

Sample code:

check hubspotClient->/batch/archive.post({
inputs: [
{id: "301"},
{id: "302"}
]
});
Search contacts

Queries contacts using filter groups, property filters, sorting criteria, and pagination.

Parameters:

NameTypeRequiredDescription
payloadPublicObjectSearchRequestYesSearch request containing filterGroups (array of filter groups), sorts, query (full-text search string), properties, limit, and after (pagination cursor).
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: CollectionResponseWithTotalSimplePublicObjectForwardPaging|error

Sample code:

hscontacts:CollectionResponseWithTotalSimplePublicObjectForwardPaging result =
check hubspotClient->/search.post({
filterGroups: [
{
filters: [
{
propertyName: "hs_lead_status",
operator: "EQ",
value: "NEW"
}
]
}
],
properties: ["firstname", "lastname", "email", "hs_lead_status"],
sorts: ["lastname"],
'limit: 20,
after: "0"
});

Sample response:

{
"total": 2,
"results": [
{
"id": "201",
"properties": {
"firstname": "Bob",
"lastname": "Johnson",
"email": "[email protected]",
"hs_lead_status": "NEW"
},
"createdAt": "2026-03-18T12:00:00.000Z",
"updatedAt": "2026-03-18T14:10:00.000Z",
"archived": false
},
{
"id": "401",
"properties": {
"firstname": "New",
"lastname": "Person",
"email": "[email protected]",
"hs_lead_status": "NEW"
},
"createdAt": "2026-03-18T14:10:00.000Z",
"updatedAt": "2026-03-18T14:10:00.000Z",
"archived": false
}
],
"paging": {
"next": {
"after": "402",
"link": "https://api.hubapi.com/crm/v3/objects/contacts/search?after=402"
}
}
}

Merge & GDPR

Merge two contacts

Merges two contact records into one, combining their properties and associations. The primary contact is kept; the other is archived.

Parameters:

NameTypeRequiredDescription
payloadPublicMergeInputYesMerge input containing primaryObjectId (the contact to keep) and objectIdToMerge (the contact to merge in and archive).
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: SimplePublicObject|error

Sample code:

hscontacts:SimplePublicObject merged = check hubspotClient->/merge.post({
primaryObjectId: "101",
objectIdToMerge: "201"
});

Sample response:

{
"id": "101",
"properties": {
"firstname": "Alice",
"lastname": "Smith",
"email": "[email protected]",
"lastmodifieddate": "2026-03-18T15:00:00.000Z"
},
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2026-03-18T15:00:00.000Z",
"archived": false
}
GDPR delete a contact

Permanently and irrecoverably deletes a contact and all associated data for GDPR compliance. This cannot be undone.

Parameters:

NameTypeRequiredDescription
payloadPublicGdprDeleteInputYesGDPR delete input containing objectId (internal contact ID) and optional idProperty to specify an alternate unique identifier.
headersmap<string|string[]>NoAdditional HTTP headers.

Returns: error?

Sample code:

check hubspotClient->/gdpr\-delete.post({
objectId: "101"
});