This module is a CFML SDK to interact with the Cordial Contact Management APIs.
Apache License, Version 2.0.
- https://github.com/coldbox-modules/cordial-sdk
- https://support.cordial.com/hc/en-us/sections/200533927-Contact-management-APIs
- Lucee 5+
- Adobe ColdFusion 2018+
- ColdBox 8+
Configure your Cordial credentials in the config/ColdBox.cfc file.
moduleSettings = {
"cordial-sdk" = {
apiKey = getSystemSetting( "CORDIAL_SDK_API_KEY", "" ),
baseURL = getSystemSetting( "CORDIAL_SDK_BASE_URL", "" ),
maxConcurrency = 10,
forceSubscribe = false
}
};| Name | Type | Required? | Default | Description |
|---|---|---|---|---|
apiKey |
String | true |
"" |
Cordial API key. Can come from CORDIAL_SDK_API_KEY or ColdBox module overrides. |
baseURL |
String | true |
"" |
Cordial account API base URL (for example, https://<your-account-host>). |
maxConcurrency |
Numeric | false |
10 |
Maximum per-batch request concurrency. Values <= 0 fall back to configured module default. |
forceSubscribe |
Boolean | false |
false |
Default forceSubscribe behavior for create(...). |
Resolve the service with WireBox:
var subscriptions = getInstance( "Subscriptions@cordial-sdk" );Creates subscriptions for one list and many subscribers.
var result = subscriptions.create(
listKey = "myListKey",
subscribers = [ "one@example.com", "two@example.com" ],
forceSubscribe = true,
maxConcurrency = 5
);| Name | Type | Required? | Default | Description |
|---|---|---|---|---|
listKey |
String | true |
The Cordial list key to set to true. |
|
subscribers |
Array | true |
Email subscribers for this operation. | |
forceSubscribe |
Boolean | false |
module setting | When true, includes forceSubscribe: true in the request payload. |
maxConcurrency |
Numeric | false |
module setting | Max async requests in each chunk. |
Behavior:
- Uses
POST /v2/contactsper valid subscriber. - Sets
channels.email.addressandchannels.email.subscribeStatus = "subscribed". - Sets dynamic list membership key (
<listKey> = true). - Invalid email entries are reported as failures and do not generate HTTP requests.
Cancels subscriptions for one list and many subscribers.
var result = subscriptions.cancel(
listKey = "myListKey",
subscribers = [ "one@example.com", "two@example.com" ],
maxConcurrency = 5
);| Name | Type | Required? | Default | Description |
|---|---|---|---|---|
listKey |
String | true |
The Cordial list key to set to false. |
|
subscribers |
Array | true |
Email subscribers for this operation. | |
maxConcurrency |
Numeric | false |
module setting | Max async requests in each chunk. |
Behavior:
- Uses
PUT /v2/contacts/email:{urlEncodedEmail}per valid subscriber. - Sets dynamic list membership key (
<listKey> = false). - Does not perform global channel unsubscribe.
- Invalid email entries are reported as failures and do not generate HTTP requests.
Both methods return an aggregate result struct:
{
success : true|false,
total : numeric,
succeeded : numeric,
failed : numeric,
results : [
{
subscriber : "email@example.com",
success : true|false,
statusCode : numeric,
response : HyperResponse|null,
error : "",
exceptionType : ""
}
]
}Notes:
successis true only whenfailed == 0.totalis the count of input subscribers.resultsincludes preflight validation failures and HTTP operation outcomes.
The Cordial SDK uses the Hyper HTTP Client under the hood.
In ModuleConfig.cfc the Hyper client is preconfigured with:
- Basic auth (
username = apiKey,password = "") - Base URL from module settings
- JSON request/response headers
binder
.map( "CordialHyperClient@cordial-sdk" )
.to( "hyper.models.HyperBuilder" )
.asSingleton()
.initWith(
username = settings.apiKey,
password = "",
baseURL = settings.baseURL,
bodyFormat = "json",
headers = {
"Content-Type" : "application/json",
"Accept" : "application/json"
}
);Because of this setup, each method only needs to provide endpoint and payload.
Unit tests use Hyper fake support and TestBox matchers.
box server start --background --noSaveSettings --noOpenBrowser
# server stays runningThen run TestBox against /tests/runner.cfm.
Integration tests are live-first and skip when required env vars are missing:
CORDIAL_SDK_API_KEYCORDIAL_SDK_BASE_URLCORDIAL_SDK_TEST_LIST_KEYCORDIAL_SDK_TEST_EMAILS(comma-separated)
These tests validate list membership changes against real Cordial contact records.