Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(sendgrid): read marketing campaigns through Single Sends
Rudy Celekli94f310943cb7
diff --git a/tests/clis/sendgrid-campaign-routes.test.cjs b/tests/clis/sendgrid-campaign-routes.test.cjsnew file mode 100644index 0000000..019b672--- /dev/null+++ b/tests/clis/sendgrid-campaign-routes.test.cjs@@ -0,0 +1,47 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')++function run(args, dryRun = false, response = null) {+ const cli = path.resolve(__dirname, '../../tools/clis/sendgrid.js')+ const source = `global.fetch = async (url, options) => {+ if (${dryRun}) throw new Error('Unexpected network request');+ const request = { url: String(url), method: options.method, body: options.body ? JSON.parse(options.body) : null };+ return { status: 200, text: async () => JSON.stringify(${JSON.stringify(response)} || request) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const result = spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000, env: {+ ...process.env, SENDGRID_API_KEY: 'fixture-secret'+ } })+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}++test('campaign list reads current Marketing Single Sends with page size', () => {+ const result = run(['campaigns', 'list', '--limit', '25'])+ assert.equal(result.method, 'GET')+ assert.equal(result.url, 'https://api.sendgrid.com/v3/marketing/singlesends?page_size=25')+ assert.equal(result.body, null)+})+test('campaign get reads a Single Send by ID', () => {+ const result = run(['campaigns', 'get', 'e2b5c7df-0026-4a86-8f35-ef134f48f600'])+ assert.equal(result.url, 'https://api.sendgrid.com/v3/marketing/singlesends/e2b5c7df-0026-4a86-8f35-ef134f48f600')+ assert.equal(result.method, 'GET')+})+test('missing campaign ID never fetches', () => {+ assert.match(run(['campaigns', 'get'], true).error, /Campaign ID required/)+})+test('campaign dry run previews the Single Sends route and masks auth', () => {+ const result = run(['campaigns', 'list', '--dry-run'], true)+ assert.equal(new URL(result.url).pathname, '/v3/marketing/singlesends')+ assert.equal(result.headers.Authorization, '***')+})++test('campaign list preserves the provider result and pagination metadata', () => {+ const response = { result: [{ id: 'fixture-send', name: 'Newsletter', status: 'draft' }], _metadata: { next: 'https://api.sendgrid.com/v3/marketing/singlesends?page_token=next' } }+ assert.deepEqual(run(['campaigns', 'list'], false, response), response)+})+test('campaign get preserves the Single Send object', () => {+ const response = { id: 'fixture-send', name: 'Newsletter', status: 'draft', send_to: { list_ids: ['fixture-list'] } }+ assert.deepEqual(run(['campaigns', 'get', 'fixture-send'], false, response), response)+})diff --git a/tools/clis/sendgrid.js b/tools/clis/sendgrid.jsindex 4699dcd..14b7858 100755--- a/tools/clis/sendgrid.js+++ b/tools/clis/sendgrid.js@@ -117,12 +117,12 @@ async function main() {case 'list': {const params = new URLSearchParams()if (args.limit) params.set('page_size', args.limit)- result = await api('GET', `/marketing/campaigns?${params}`)+ result = await api('GET', `/marketing/singlesends?${params}`)break}case 'get':if (!rest[0]) { result = { error: 'Campaign ID required' }; break }- result = await api('GET', `/marketing/campaigns/${rest[0]}`)+ result = await api('GET', `/marketing/singlesends/${rest[0]}`)breakdefault:result = { error: 'Unknown campaigns subcommand. Use: list, get' }@@ -196,7 +196,7 @@ async function main() {usage: {send: 'send --from <email> --to <email> [--subject <subject>] [--html <html>] [--text <text>] [--template-id <id> (d-... supplies its own subject)] [--template-data <json>]',contacts: 'contacts [list|add|search] [--email <email>] [--first-name <name>] [--last-name <name>] [--list-ids <ids>] [--query <sgql>]',- campaigns: 'campaigns [list|get] [id] [--limit <n>]',+ campaigns: 'campaigns [list|get] [single_send_id] [--limit <n>] (Marketing Single Sends)',stats: 'stats get [--start-date <YYYY-MM-DD>] [--end-date <YYYY-MM-DD>]',bounces: 'bounces list [--start-time <ts>] [--end-time <ts>] [--limit <n>]','spam-reports': 'spam-reports list [--start-time <ts>] [--end-time <ts>] [--limit <n>]',diff --git a/tools/integrations/sendgrid.md b/tools/integrations/sendgrid.mdindex aa54671..2bb9b40 100644--- a/tools/integrations/sendgrid.md+++ b/tools/integrations/sendgrid.md@@ -82,6 +82,17 @@ POST https://api.sendgrid.com/v3/marketing/contacts/search}```+### Read marketing campaigns (Single Sends)++The CLI's `campaigns list` and `campaigns get <id>` commands read Marketing Single Sends:++```bash+GET https://api.sendgrid.com/v3/marketing/singlesends?page_size=25+GET https://api.sendgrid.com/v3/marketing/singlesends/{single_send_id}+```++List responses contain `result` and `_metadata`; get responses contain the Single Send object. The CLI prints these provider responses without reshaping them. These commands use the current Marketing API, which is also used by the contact commands. Legacy Marketing Campaigns use the separate `/v3/campaigns` API and are not supported by these commands.+### Get email statistics```bash