Skip to main content

Actions

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

ClientPurpose
ClientManages HubSpot CRM discount objects: CRUD, batch operations, and search.

Client

Manages HubSpot CRM discount objects: CRUD, batch operations, and search.

Configuration

FieldTypeDefaultDescription
authhttp:BearerTokenConfig|OAuth2RefreshTokenGrantConfig|ApiKeysConfigRequiredAuthentication configuration: OAuth 2.0 refresh token, bearer token, or API keys.
httpVersionhttp:HttpVersionhttp:HTTP_2_0HTTP protocol version.
timeoutdecimal30Request timeout in seconds.
retryConfighttp:RetryConfig()Retry configuration for failed requests.
circuitBreakerhttp:CircuitBreakerConfig()Circuit breaker configuration.
secureSockethttp:ClientSecureSocket()SSL/TLS configuration.
proxyhttp:ProxyConfig()Proxy server configuration.
validationbooleantrueEnable/disable payload validation.

Initializing the client

import ballerinax/hubspot.crm.commerce.discounts;

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

discounts:Client discountsClient = check new ({
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
});

Operations

Single record operations

List discounts

Signature: get /

Retrieves a page of discount records with optional property selection, associations, and pagination.

Parameters:

NameTypeRequiredDescription
headersmap<string|string[]>NoRequest headers.
queriesGetCrmV3ObjectsDiscountsQueriesNoQuery parameters including 'limit, after, properties, propertiesWithHistory, and associations.

Returns: CollectionResponseSimplePublicObjectWithAssociationsForwardPaging|error

Sample code:

discounts:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging response =
check discountsClient->/.get();

Sample response:

{
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_createdate": "2026-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2026-01-15T10:30:00.000Z"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": {
"next": {
"after": "12345",
"link": "https://api.hubapi.com/crm/v3/objects/discounts?after=12345"
}
}
}
Create a discount

Signature: post /

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

Parameters:

NameTypeRequiredDescription
payloadSimplePublicObjectInputForCreateYesDiscount properties and optional associations.
headersmap<string|string[]>NoRequest headers.

Returns: SimplePublicObject|error

Sample code:

discounts:SimplePublicObject response = check discountsClient->/.post({
properties: {
"hs_label": "Summer Sale",
"hs_duration": "ONCE",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_sort_order": "2"
}
});

Sample response:

{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_duration": "ONCE",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_sort_order": "2",
"hs_createdate": "2026-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2026-01-15T10:30:00.000Z"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
Read a discount

Signature: get /[string discountId]

Retrieves a single discount record by its ID, with optional property selection.

Parameters:

NameTypeRequiredDescription
discountIdstringYesThe ID of the discount to retrieve.
headersmap<string|string[]>NoRequest headers.
queriesGetCrmV3ObjectsDiscountsDiscountIdQueriesNoQuery parameters including properties, propertiesWithHistory, and associations.

Returns: SimplePublicObjectWithAssociations|error

Sample code:

discounts:SimplePublicObjectWithAssociations response =
check discountsClient->/[discountId].get();

Sample response:

{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_createdate": "2026-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2026-01-15T10:30:00.000Z"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
Update a discount

Signature: patch /[string discountId]

Updates an existing discount record's properties by its ID.

Parameters:

NameTypeRequiredDescription
discountIdstringYesThe ID of the discount to update.
payloadSimplePublicObjectInputYesThe properties to update.
headersmap<string|string[]>NoRequest headers.
queriesPatchCrmV3ObjectsDiscountsDiscountIdQueriesNoQuery parameters including idProperty.

Returns: SimplePublicObject|error

Sample code:

discounts:SimplePublicObject response = check discountsClient->/[discountId].patch({
properties: {
"hs_value": "20"
}
});

Sample response:

{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "20",
"hs_createdate": "2026-01-15T10:30:00.000Z",
"hs_lastmodifieddate": "2026-01-16T08:00:00.000Z"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-16T08:00:00.000Z",
"archived": false
}
Archive a discount

Signature: delete /[string discountId]

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

Parameters:

NameTypeRequiredDescription
discountIdstringYesThe ID of the discount to archive.
headersmap<string|string[]>NoRequest headers.

Returns: error?

Sample code:

check discountsClient->/[discountId].delete();

Batch operations

Create a batch of discounts

Signature: post /batch/create

Creates multiple discount records in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectInputForCreateYesBatch of discount inputs to create.
headersmap<string|string[]>NoRequest headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

discounts:BatchResponseSimplePublicObject|discounts:BatchResponseSimplePublicObjectWithErrors response =
check discountsClient->/batch/create.post({
inputs: [
{
properties: {
"hs_label": "Black Friday Deal",
"hs_duration": "ONCE",
"hs_type": "PERCENTAGE",
"hs_value": "25",
"hs_sort_order": "1"
}
},
{
properties: {
"hs_label": "Cyber Monday Deal",
"hs_duration": "ONCE",
"hs_type": "FIXED",
"hs_value": "50",
"hs_sort_order": "2"
}
}
]
});

Sample response:

{
"completedAt": "2026-01-15T10:30:00.000Z",
"startedAt": "2026-01-15T10:30:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Black Friday Deal",
"hs_type": "PERCENTAGE",
"hs_value": "25"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
},
{
"id": "12346",
"properties": {
"hs_label": "Cyber Monday Deal",
"hs_type": "FIXED",
"hs_value": "50"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
]
}
Read a batch of discounts by internal ID, or unique property values

Signature: post /batch/read

Reads multiple discount records by their IDs or a unique property value in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchReadInputSimplePublicObjectIdYesBatch of discount IDs or unique property identifiers to read.
headersmap<string|string[]>NoRequest headers.
queriesPostCrmV3ObjectsDiscountsBatchReadQueriesNoQuery parameters including archived.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

discounts:BatchResponseSimplePublicObject|discounts:BatchResponseSimplePublicObjectWithErrors response =
check discountsClient->/batch/read.post({
inputs: [
{ id: "12345" },
{ id: "12346" }
],
properties: ["hs_label", "hs_type", "hs_value"]
});

Sample response:

{
"completedAt": "2026-01-15T10:30:01.000Z",
"startedAt": "2026-01-15T10:30:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Black Friday Deal",
"hs_type": "PERCENTAGE",
"hs_value": "25"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
},
{
"id": "12346",
"properties": {
"hs_label": "Cyber Monday Deal",
"hs_type": "FIXED",
"hs_value": "50"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
]
}
Update a batch of discounts

Signature: post /batch/update

Updates multiple discount records' properties in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputYesBatch of discount updates with IDs and properties.
headersmap<string|string[]>NoRequest headers.

Returns: BatchResponseSimplePublicObject|BatchResponseSimplePublicObjectWithErrors|error

Sample code:

discounts:BatchResponseSimplePublicObject|discounts:BatchResponseSimplePublicObjectWithErrors response =
check discountsClient->/batch/update.post({
inputs: [
{
id: "12345",
properties: {
"hs_value": "30"
}
},
{
id: "12346",
properties: {
"hs_value": "60"
}
}
]
});

Sample response:

{
"completedAt": "2026-01-16T08:00:01.000Z",
"startedAt": "2026-01-16T08:00:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Black Friday Deal",
"hs_type": "PERCENTAGE",
"hs_value": "30"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-16T08:00:00.000Z",
"archived": false
},
{
"id": "12346",
"properties": {
"hs_label": "Cyber Monday Deal",
"hs_type": "FIXED",
"hs_value": "60"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-16T08:00:00.000Z",
"archived": false
}
]
}
Archive a batch of discounts by ID

Signature: post /batch/archive

Archives (soft-deletes) multiple discount records by their IDs in a single request.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectIdYesBatch of discount IDs to archive.
headersmap<string|string[]>NoRequest headers.

Returns: error?

Sample code:

check discountsClient->/batch/archive.post({
inputs: [
{ id: "12345" },
{ id: "12346" }
]
});
Create or update a batch of discounts by unique property values

Signature: post /batch/upsert

Creates or updates multiple discount records using unique property values to determine whether to create or update.

Parameters:

NameTypeRequiredDescription
payloadBatchInputSimplePublicObjectBatchInputUpsertYesBatch of discount upsert inputs with ID properties and values.
headersmap<string|string[]>NoRequest headers.

Returns: BatchResponseSimplePublicUpsertObject|BatchResponseSimplePublicUpsertObjectWithErrors|error

Sample code:

discounts:BatchResponseSimplePublicUpsertObject|discounts:BatchResponseSimplePublicUpsertObjectWithErrors response =
check discountsClient->/batch/upsert.post({
inputs: [
{
idProperty: "hs_label",
id: "Summer Sale",
properties: {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_duration": "ONCE"
}
}
]
});

Sample response:

{
"completedAt": "2026-01-15T10:30:01.000Z",
"startedAt": "2026-01-15T10:30:00.000Z",
"status": "COMPLETE",
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "15"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false,
"new": true
}
]
}
Search discounts

Signature: post /search

Searches for discount records using filters, query text, sorting, and property selection.

Parameters:

NameTypeRequiredDescription
payloadPublicObjectSearchRequestYesSearch request with optional query, filterGroups, sorts, properties, 'limit, and after.
headersmap<string|string[]>NoRequest headers.

Returns: CollectionResponseWithTotalSimplePublicObjectForwardPaging|error

Sample code:

discounts:CollectionResponseWithTotalSimplePublicObjectForwardPaging response =
check discountsClient->/search.post({
filterGroups: [
{
filters: [
{
propertyName: "hs_type",
operator: "EQ",
value: "PERCENTAGE"
}
]
}
],
sorts: ["hs_value"],
properties: ["hs_label", "hs_type", "hs_value", "hs_duration"],
'limit: 10
});

Sample response:

{
"total": 1,
"results": [
{
"id": "12345",
"properties": {
"hs_label": "Summer Sale",
"hs_type": "PERCENTAGE",
"hs_value": "15",
"hs_duration": "ONCE"
},
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z",
"archived": false
}
],
"paging": {}
}