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(zapier): send catch hooks without management credentials
Rudy Celekli946caccb2c55
diff --git a/tests/clis/zapier-webhook.test.cjs b/tests/clis/zapier-webhook.test.cjsnew file mode 100644index 0000000..bc50527--- /dev/null+++ b/tests/clis/zapier-webhook.test.cjs@@ -0,0 +1,53 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/zapier.js')+function run(args, { key, status = 200, body = '{"accepted":true}', network = true } = {}) {+ const code = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected network request');+ return { status: ${status}, ok: ${status >= 200 && status < 300}, text: async () => JSON.stringify({ url, ...options, response: ${JSON.stringify(body)} }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const env = { ...process.env }; delete env.ZAPIER_API_KEY+ if (key !== undefined) env.ZAPIER_API_KEY = key+ return spawnSync(process.execPath, ['-e', code], { encoding: 'utf8', env })+}+const hook = ['hooks', 'send', '--url', 'https://hooks.zapier.com/hooks/catch/test/example/', '--data', '{"event":"created","value":0}']+test('catch hook sends JSON without requiring an unrelated management API key', () => {+ const r = run(hook)+ assert.equal(r.status, 0, r.stderr)+ const p = JSON.parse(r.stdout)+ assert.equal(p.url, hook[3]); assert.equal(p.method, 'POST')+ assert.deepEqual(p.headers, { 'Content-Type': 'application/json' })+ assert.deepEqual(JSON.parse(p.body), { event: 'created', value: 0 })+})+test('configured management key is never sent to a catch hook', () => {+ const r = run(hook, { key: 'management-secret' }); assert.equal(r.status, 0, r.stderr)+ assert.ok(!r.stdout.includes('management-secret'))+})+test('catch-hook dry run works without credentials and never fetches', () => {+ const r = run([...hook, '--dry-run'], { network: false }); assert.equal(r.status, 0, r.stderr)+ const p = JSON.parse(r.stdout); assert.equal(p._dry_run, true)+ assert.deepEqual(p.headers, { 'Content-Type': 'application/json' })+})+test('management commands still require their API key before fetching', () => {+ const r = run(['zaps', 'list'], { network: false }); assert.equal(r.status, 1)+ assert.match(r.stderr, /ZAPIER_API_KEY/)+})+test('management key and masked management preview are preserved', () => {+ const r = run(['zaps', 'list'], { key: 'management-secret' }); assert.equal(r.status, 0, r.stderr)+ assert.equal(JSON.parse(r.stdout).headers['X-API-Key'], 'management-secret')+ const d = run(['zaps', 'list', '--dry-run'], { key: 'management-secret', network: false })+ assert.equal(JSON.parse(d.stdout).headers['X-API-Key'], '***')+})+test('HTTP 404 from a disabled hook exits unsuccessfully', () => {+ const r = run(hook, { key: 'not-needed', status: 404, body: '{"error":"hook disabled"}' })+ assert.equal(r.status, 1); assert.match(r.stderr, /404/)+})+test('invalid webhook inputs remain local and help works without credentials', () => {+ for (const args of [['hooks', 'send', '--url', 'http://example.test', '--data', '{}'], ['hooks', 'send', '--url', 'https://example.test', '--data', 'not-json']]) {+ const r = run(args, { network: false }); assert.ok(JSON.parse(r.stdout).error)+ }+ const r = run([], { network: false }); assert.equal(r.status, 0)+ assert.ok(JSON.parse(r.stdout).usage.hooks)+})diff --git a/tools/clis/zapier.js b/tools/clis/zapier.jsindex c15274c..ae1ab4e 100755--- a/tools/clis/zapier.js+++ b/tools/clis/zapier.js@@ -4,12 +4,8 @@ const rawArgs = process.argv.slice(2)const API_KEY = process.env.ZAPIER_API_KEYconst BASE_URL = 'https://api.zapier.com/v1'-if ((!API_KEY) && rawArgs.length > 0) {- console.error(JSON.stringify({ error: 'ZAPIER_API_KEY environment variable required' }))- process.exit(1)-}-async function api(method, path, body) {+ if (!API_KEY) throw new Error('ZAPIER_API_KEY environment variable required')if (args['dry-run']) {return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'X-API-Key': '***', 'Content-Type': 'application/json' }, body: body || undefined }}@@ -39,6 +35,7 @@ async function webhookPost(url, data) {body: JSON.stringify(data),})const text = await res.text()+ if (!res.ok) throw new Error(`Webhook failed (HTTP ${res.status}): ${text}`)try {return JSON.parse(text)} catch {diff --git a/tools/integrations/zapier.md b/tools/integrations/zapier.mdindex 02788be..0b2994d 100644--- a/tools/integrations/zapier.md+++ b/tools/integrations/zapier.md@@ -146,6 +146,14 @@ GET https://api.zapier.com/v1/profiles/me## Webhooks (Triggers)+Catch Hook URLs do not require `ZAPIER_API_KEY`; the unique URL identifies the hook. The local CLI requires that key only for its management API commands, and never attaches it to a webhook request.++```bash+node tools/clis/zapier.js hooks send --url "https://hooks.zapier.com/hooks/catch/{account_id}/{hook_id}/" --data '{"event":"user.created"}'+```++Use `--dry-run` to preview the JSON POST without sending it. Treat the hook URL as a secret. Non-success HTTP responses exit unsuccessfully; an HTTP 200 only confirms reception, not completion of the Zap. [Zapier documents the hook setup and response behavior](https://help.zapier.com/hc/en-us/articles/8496288690317-Trigger-Zap-workflows-from-webhooks).+### Catch Hook (receive data)Create a "Webhooks by Zapier" trigger to receive data: