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(beehiiv): send HTML post content in body_content
Rudy Celekli0aa62246f5d1
diff --git a/tests/clis/beehiiv-post-content.test.cjs b/tests/clis/beehiiv-post-content.test.cjsnew file mode 100644index 0000000..c50b15f--- /dev/null+++ b/tests/clis/beehiiv-post-content.test.cjs@@ -0,0 +1,37 @@+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) {+ const cli = path.resolve(__dirname, '../../tools/clis/beehiiv.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(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, BEEHIIV_API_KEY: 'fixture-secret'+ } })+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}++test('HTML post creation sends the API body_content field', () => {+ const html = '<p>Launch: <a href="https://example.com/?a=1&b=2">Details</a></p>'+ const result = run(['posts', 'create', '--publication', 'pub_123', '--title', 'Launch', '--content', html, '--subtitle', 'This week', '--status', 'draft'])+ assert.equal(result.method, 'POST')+ assert.equal(result.url, 'https://api.beehiiv.com/v2/publications/pub_123/posts')+ assert.deepEqual(result.body, { title: 'Launch', subtitle: 'This week', body_content: html, status: 'draft' })+})+test('omitting post content stops before a network request', () => {+ assert.match(run(['posts', 'create', '--publication', 'pub_123', '--title', 'Empty'], true).error, /content.*required/i)+})+test('bare --content is rejected instead of sending a boolean', () => {+ assert.match(run(['posts', 'create', '--publication', 'pub_123', '--title', 'Empty', '--content'], true).error, /content.*required/i)+})+test('post dry run previews raw HTML and redacts authentication', () => {+ const result = run(['posts', 'create', '--publication', 'pub_123', '--title', 'Launch', '--content', '<p>News</p>', '--dry-run'], true)+ assert.equal(result.body.body_content, '<p>News</p>')+ assert.equal(result.headers.Authorization, '***')+})diff --git a/tools/clis/beehiiv.js b/tools/clis/beehiiv.jsindex e13b282..ebf8e59 100755--- a/tools/clis/beehiiv.js+++ b/tools/clis/beehiiv.js@@ -160,9 +160,9 @@ async function main() {if (!pubId) { result = { error: '--publication required' }; break }const title = args.titleif (!title) { result = { error: '--title required' }; break }- const body = { title }+ if (typeof args.content !== 'string' || !args.content.trim()) { result = { error: '--content required (HTML post body)' }; break }+ const body = { title, body_content: args.content }if (args.subtitle) body.subtitle = args.subtitle- if (args.content) body.content = args.contentif (args.status) body.status = args.statusresult = await api('POST', `/publications/${pubId}/posts`, body)break@@ -235,7 +235,7 @@ async function main() {usage: {publications: 'publications [list | get --publication <id>]',subscriptions: 'subscriptions [list | get --id <id> | create --email <email> | update --id <id> | delete --id <id>] --publication <id>',- posts: 'posts [list | get --id <id> | create --title <title> | delete --id <id>] --publication <id>',+ posts: 'posts [list | get --id <id> | create --title <title> --content <html> | delete --id <id>] --publication <id>',segments: 'segments [list | get --id <id>] --publication <id>',automations: 'automations [list | get --id <id>] --publication <id>','referral-program': 'referral-program [get] --publication <id>',diff --git a/tools/integrations/beehiiv.md b/tools/integrations/beehiiv.mdindex 25170a7..82af0f0 100644--- a/tools/integrations/beehiiv.md+++ b/tools/integrations/beehiiv.md@@ -77,7 +77,7 @@ DELETE https://api.beehiiv.com/v2/publications/{publicationId}/subscriptions/{suGET https://api.beehiiv.com/v2/publications/{publicationId}/posts?limit=10&status=confirmed```-### Create post (Enterprise only)+### Create post (Max and Enterprise plans)```bashPOST https://api.beehiiv.com/v2/publications/{publicationId}/posts@@ -85,11 +85,13 @@ POST https://api.beehiiv.com/v2/publications/{publicationId}/posts{"title": "Weekly Update","subtitle": "What happened this week",- "content": "<p>Hello subscribers...</p>",+ "body_content": "<p>Hello subscribers...</p>","status": "draft"}```+The API requires `body_content` or structured `blocks`. The CLI accepts raw HTML through `--content` and sends it as `body_content`.+### List segments```bash