Skip to main content

Actions

The ballerinax/hubspot.crm.commerce.carts package exposes the following clients:

ClientPurpose
ClientManages HubSpot cart objects: CRUD, search, and batch operations via the HubSpot CRM v3 API.

Client

Manages HubSpot cart objects: CRUD, search, and batch operations via the HubSpot CRM v3 API.

Configuration

FieldTypeDefaultDescription
authhttp:BearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredAuthentication configuration: OAuth 2.0 refresh token, bearer token, or HubSpot private app 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.
compressionCompressionCOMPRESSION_AUTOHTTP compression setting.
circuitBreakerCircuitBreakerConfig()Circuit breaker configuration for fault tolerance.
cacheCacheConfig{}HTTP response cache configuration.

Initializing the client

import ballerina/oauth2;
import ballerinax/hubspot.crm.commerce.carts as hscarts;

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

hscarts:ConnectionConfig config = {
auth: {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};
final hscarts:Client hubspotCarts = check new (config);

Operations

Cart CRUD

List carts

Signature: get /carts

Retrieves a paginated list of cart objects, optionally including associations and property history.

Parameters:

NameTypeRequiredDescription
headersmap<string&#124;string[]>NoOptional HTTP headers.
queries.limitint:Signed32NoMaximum number of results per page (default 10).
queries.afterstringNoCursor token for the next page of results.
queries.propertiesstring[]NoList of property names to include in the response.
queries.propertiesWithHistorystring[]NoList of property names to include with their change history.
queries.associationsstring[]NoList of association types to retrieve with each cart.
queries.archivedbooleanNoWhether to return archived carts (default false).

Returns: CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error

Sample code:

hscarts:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response =
check hubspotCarts->/carts(properties = ["hs_source_store", "hs_total_price"]);

Sample response:

{
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": {
"next": {
"after": "12345679",
"link": "https://api.hubapi.com/crm/v3/objects/carts?after=12345679"
}
}
}
Create a cart

Signature: post /carts

Creates a new cart object with the specified properties and optional associations.

Parameters:

NameTypeRequiredDescription
payloadSimplePublicObjectInputForCreateYesCart properties and optional associations.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: SimplePublicObject|error

Sample code:

hscarts:SimplePublicObject response = check hubspotCarts->/carts.post(
payload = {
properties: {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "36.25",
"hs_tags": "donuts, bagels"
}
}
);

Sample response:

{
"id": "12345678",
"properties": {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "36.25",
"hs_tags": "donuts, bagels",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
Read a cart

Signature: get /carts/[cartId]

Retrieves a single cart by its ID, optionally including associations and property history.

Parameters:

NameTypeRequiredDescription
cartIdstringYesThe HubSpot cart ID.
headersmap<string&#124;string[]>NoOptional HTTP headers.
queries.propertiesstring[]NoList of property names to include in the response.
queries.propertiesWithHistorystring[]NoList of property names to include with their change history.
queries.associationsstring[]NoList of association types to retrieve.
queries.archivedbooleanNoWhether to return the cart if archived (default false).
queries.idPropertystringNoThe property to use as the unique identifier (defaults to hs_object_id).

Returns: SimplePublicObjectWithAssociations|error

Sample code:

hscarts:SimplePublicObjectWithAssociations response =
check hubspotCarts->/carts/["12345678"]();

Sample response:

{
"id": "12345678",
"properties": {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "36.25",
"hs_tags": "donuts, bagels",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
Update a cart

Signature: patch /carts/[cartId]

Updates an existing cart's properties by its ID.

Parameters:

NameTypeRequiredDescription
cartIdstringYesThe HubSpot cart ID.
payloadSimplePublicObjectInputYesCart properties to update.
headersmap<string&#124;string[]>NoOptional HTTP headers.
queries.idPropertystringNoThe property to use as the unique identifier.

Returns: SimplePublicObject|error

Sample code:

hscarts:SimplePublicObject response = check hubspotCarts->/carts/["12345678"].patch(
payload = {
properties: {
"hs_tax": "48.75"
}
}
);

Sample response:

{
"id": "12345678",
"properties": {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "48.75",
"hs_tags": "donuts, bagels",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T11:00:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
}
Archive a cart

Signature: delete /carts/[cartId]

Archives (soft-deletes) a cart by its ID.

Parameters:

NameTypeRequiredDescription
cartIdstringYesThe HubSpot cart ID.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: error?

Sample code:

_ = check hubspotCarts->/carts/["12345678"].delete();
Search carts

Signature: post /carts/search

Searches for carts matching the given filter criteria, with support for property filters, sorting, and pagination.

Parameters:

NameTypeRequiredDescription
payloadPublicObjectSearchRequestYesSearch request with filter groups, query string, sorting, and pagination options.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: CollectionResponseWithTotalSimplePublicObjectForwardPaging|error

Sample code:

hscarts:CollectionResponseWithTotalSimplePublicObjectForwardPaging response =
check hubspotCarts->/carts/search.post({
filterGroups: [
{
filters: [
{
propertyName: "hs_tags",
value: "donuts, bagels",
operator: "EQ"
}
]
}
],
properties: ["hs_source_store", "hs_total_price"]
});

Sample response:

{
"total": 1,
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "Dog Cafe: Italy",
"hs_total_price": "500",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": null
}

Batch operations

Batch create carts

Signature: post /carts/batch/create

Creates multiple cart objects in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectInputForCreateYesBatch input containing an array of cart creation payloads.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscarts:BatchResponseSimplePublicObject response =
check hubspotCarts->/carts/batch/create.post({
inputs: [
{
properties: {
"hs_source_store": "ABC Cafe",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "36.25",
"hs_tags": "donuts, coffee"
}
},
{
properties: {
"hs_source_store": "XYZ Cafe",
"hs_total_price": "400",
"hs_currency_code": "USD",
"hs_tax": "23.25",
"hs_tags": "bagels, tea"
}
}
]
});

Sample response:

{
"completedAt": "2025-01-15T10:30:01.000Z",
"startedAt": "2025-01-15T10:30:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "ABC Cafe",
"hs_total_price": "500",
"hs_currency_code": "USD",
"hs_tax": "36.25",
"hs_tags": "donuts, coffee",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
},
{
"id": "12345679",
"properties": {
"hs_source_store": "XYZ Cafe",
"hs_total_price": "400",
"hs_currency_code": "USD",
"hs_tax": "23.25",
"hs_tags": "bagels, tea",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T10:30:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
]
}
Read a batch of carts by internal ID, or unique property values

Signature: post /carts/batch/read

Retrieves multiple carts by their IDs or a unique property, with optional property selection.

Parameters:

NameTypeRequiredDescription
payloadBatchReadInputSimplePublicObjectIdYesBatch input containing cart IDs, optional properties, and an optional ID property name.
headersmap<string&#124;string[]>NoOptional HTTP headers.
queries.archivedbooleanNoWhether to include archived carts (default false).

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscarts:BatchResponseSimplePublicObject|hscarts:BatchResponseSimplePublicObjectWithErrors response =
check hubspotCarts->/carts/batch/read.post({
inputs: [
{id: "12345678"},
{id: "12345679"}
],
properties: ["hs_source_store", "hs_total_price", "hs_tags"]
});

Sample response:

{
"completedAt": "2025-01-15T10:30:01.000Z",
"startedAt": "2025-01-15T10:30:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "ABC Cafe",
"hs_total_price": "500",
"hs_tags": "donuts, coffee"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
},
{
"id": "12345679",
"properties": {
"hs_source_store": "XYZ Cafe",
"hs_total_price": "400",
"hs_tags": "bagels, tea"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T10:30:00.000Z",
"archived": false
}
]
}
Update a batch of carts

Signature: post /carts/batch/update

Updates properties on multiple carts in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputYesBatch input containing cart IDs and properties to update.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

hscarts:BatchResponseSimplePublicObject|hscarts:BatchResponseSimplePublicObjectWithErrors response =
check hubspotCarts->/carts/batch/update.post({
inputs: [
{id: "12345678", properties: {"hs_total_price": "450", "hs_cart_discount": "10"}},
{id: "12345679", properties: {"hs_total_price": "370", "hs_cart_discount": "10"}}
]
});

Sample response:

{
"completedAt": "2025-01-15T11:00:01.000Z",
"startedAt": "2025-01-15T11:00:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "ABC Cafe",
"hs_total_price": "450",
"hs_cart_discount": "10",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T11:00:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
},
{
"id": "12345679",
"properties": {
"hs_source_store": "XYZ Cafe",
"hs_total_price": "370",
"hs_cart_discount": "10",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T11:00:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false
}
]
}
Create or update a batch of carts by unique property values

Signature: post /carts/batch/upsert

Creates or updates multiple carts in a single request, matched by a unique property value.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputUpsertYesBatch input containing cart identifiers and properties to upsert.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors|error

Sample code:

hscarts:BatchResponseSimplePublicUpsertObject|hscarts:BatchResponseSimplePublicUpsertObjectWithErrors response =
check hubspotCarts->/carts/batch/upsert.post({
inputs: [
{
id: "12345678",
properties: {
"hs_source_store": "ABC Cafe",
"hs_total_price": "550",
"hs_currency_code": "USD"
}
}
]
});

Sample response:

{
"completedAt": "2025-01-15T11:00:01.000Z",
"startedAt": "2025-01-15T11:00:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345678",
"properties": {
"hs_source_store": "ABC Cafe",
"hs_total_price": "550",
"hs_currency_code": "USD",
"hs_createdate": "2025-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2025-01-15T11:00:00.000Z"
},
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-15T11:00:00.000Z",
"archived": false,
"new": false
}
]
}
Archive a batch of carts by ID

Signature: post /carts/batch/archive

Archives (soft-deletes) multiple carts in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectIdYesBatch input containing the IDs of carts to archive.
headersmap<string&#124;string[]>NoOptional HTTP headers.

Returns: error?

Sample code:

_ = check hubspotCarts->/carts/batch/archive.post({
inputs: [
{id: "12345678"},
{id: "12345679"}
]
});