BoxLang 🚀 A New JVM Dynamic Language Learn More...
This module is a CFML SDK to interact with the Cordial Contact Management APIs.
Apache License, Version 2.0.
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 = [ "[email protected]", "[email protected]" ],
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:
POST /v2/contacts per valid subscriber.channels.email.address and
channels.email.subscribeStatus = "subscribed".<listKey> = true).Cancels subscriptions for one list and many subscribers.
var result = subscriptions.cancel(
listKey = "myListKey",
subscribers = [ "[email protected]", "[email protected]" ],
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:
PUT /v2/contacts/email:{urlEncodedEmail} per
valid subscriber.<listKey> = false).Both methods return an aggregate result struct:
{
success : true|false,
total : numeric,
succeeded : numeric,
failed : numeric,
results : [
{
subscriber : "[email protected]",
success : true|false,
statusCode : numeric,
response : HyperResponse|null,
error : "",
exceptionType : ""
}
]
}
Notes:
success is true only when failed == 0.total is the count of input subscribers.results includes 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:
username = apiKey, password = "")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 running
Then run TestBox against /tests/runner.cfm.
Integration tests are live-first and skip when required env vars are missing:
CORDIAL_SDK_API_KEY
CORDIAL_SDK_BASE_URL
CORDIAL_SDK_TEST_LIST_KEY
CORDIAL_SDK_TEST_EMAILS (comma-separated)These tests validate list membership changes against real Cordial contact records.
$
box install cordial-sdk