@create-send/node-js
v0.1.0
Published
Node.js SDK for the Campaign Monitor API.
Readme
createsend-nodejs
Node.js SDK for the Campaign Monitor API
Package managers
Examples below use npm. For pnpm or Yarn, swap commands as follows:
| Task | npm | pnpm | Yarn |
| --- | --- | --- | --- |
| Add to your project | npm install @create-send/node-js | pnpm add @create-send/node-js | yarn add @create-send/node-js |
| Install dependencies (dev) | npm install | pnpm install | yarn |
| Run a package script | npm run <name> | pnpm <name> | yarn <name> |
Install
npm install @create-send/node-jsUsage
import { Createsend } from '@create-send/node-js';
const cs = new Createsend(process.env.CREATESEND_API_KEY);
const { data, error } = await cs.clients.pagedCampaigns({
id: 'CLIENT_ID',
query: { page: 1, pageSize: 50 },
});
if (error) {
console.error(error.name, error.message);
} else {
console.log(data);
}The constructor accepts an API key (falls back to CREATESEND_API_KEY) and options:
new Createsend(apiKey, {
baseUrl: 'https://api.createsend.com/api/v3.4',
userAgent: 'my-app/1.0',
fetch: customFetch, // optional override
});All resource methods return Promise<Response<T>> — a discriminated union of { data, error: null } or { data: null, error }. Errors are never thrown by API calls (the constructor will throw if the API key is missing).
Examples
Each method takes a single options object combining path params, an optional query object, and an optional body. The data shape on success is typed from the OpenAPI spec.
Campaign summary
GET /campaigns/{id}/summary.json
const { data, error } = await cs.campaigns.summaryWithName({ id: 'CAMPAIGN_ID' });
if (data) {
console.log(data.Recipients, data.TotalOpened, data.Clicks, data.WebVersionURL);
}Campaign opens
GET /campaigns/{id}/opens.json — date (lower bound) is required; pagination optional.
const { data } = await cs.campaigns.getCampaignOpens({
id: 'CAMPAIGN_ID',
query: {
date: '2026-01-01',
page: 1,
pageSize: 1000,
orderField: 'date',
orderDirection: 'desc',
},
});
console.log(data?.Results, data?.TotalNumberOfRecords);Campaign clicks
GET /campaigns/{id}/clicks.json
const { data } = await cs.campaigns.getCampaignClicks({
id: 'CAMPAIGN_ID',
query: { date: '2026-01-01', page: 1, pageSize: 1000 },
});
for (const click of data?.Results ?? []) {
console.log(click.EmailAddress, click.URL, click.Date);
}Subscriber history
GET /subscribers/{listid}/history.json — full open/click/unsubscribe trail for one subscriber.
const { data } = await cs.subscribers.getSubscriberHistory({
listId: 'LIST_ID',
query: { email: '[email protected]' },
});
console.log(data); // array of campaign/automation eventsAdd a subscriber to a list
POST /subscribers/{listid}.json
const { data, error } = await cs.subscribersConsentToTrack.addSubscribersConsentToTrack({
listId: 'LIST_ID',
body: {
EmailAddress: '[email protected]',
Name: 'Jane Example',
CustomFields: [
{ Key: 'website', Value: 'https://example.com' },
],
Resubscribe: true,
RestartSubscriptionBasedAutoresponders: false,
ConsentToTrack: 'Yes',
},
});
if (error) console.error(error.statusCode, error.message);
else console.log('subscribed:', data);List stats
GET /lists/{listid}/stats.json
const { data } = await cs.lists.getListStats({ listId: 'LIST_ID' });
console.log(
data?.TotalActiveSubscribers,
data?.TotalUnsubscribes,
data?.TotalBounces,
);Regenerating from the OpenAPI spec
The resource classes and per-operation interfaces under src/ are generated from spec/createsend-openapi.yaml.
npm run generateTo update for a new spec version, replace spec/createsend-openapi.yaml and re-run the script. Files marked // DO NOT EDIT — generated by scripts/generate.ts will be overwritten; hand edits belong in src/createsend.ts, src/interfaces.ts, src/common/, and src/index.ts (between the GENERATED:* markers the generator manages its own block; the rest is yours).
Build
npm install
npm run generate
npm run typecheck
npm run build