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(apollo): authenticate and use GET for organization enrichment
Rudy Celekli9ef7e9a802db
diff --git a/tests/clis/apollo-enrichment.test.cjs b/tests/clis/apollo-enrichment.test.cjsnew file mode 100644index 0000000..35a15eb--- /dev/null+++ b/tests/clis/apollo-enrichment.test.cjs@@ -0,0 +1,61 @@+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/apollo.js')+function run(args, oracle = '') {+ const code = `global.fetch = async (url, options) => {+ const assert = require('node:assert/strict');+ const parsed = new URL(url);+ const body = options.body ? JSON.parse(options.body) : null;+ ${oracle}+ return new Response(JSON.stringify({accepted:true, url, body}), {status:200});+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', code], {+ encoding: 'utf8', timeout: 10000,+ env: { ...process.env, APOLLO_API_KEY: 'fixture-token' },+ })+}+function result(r) { assert.equal(r.status, 0, r.stderr); return JSON.parse(r.stdout) }++test('organization enrichment uses authenticated GET query without a request body', () => {+ const p = result(run(['organizations','enrich','--domain','example.com'], `+ assert.equal(options.method, 'GET');+ assert.equal(parsed.pathname, '/api/v1/organizations/enrich');+ assert.equal(parsed.searchParams.get('domain'), 'example.com');+ assert.equal(options.body, undefined);+ assert.equal(options.headers['x-api-key'], 'fixture-token');+ `))+ assert.equal(p.accepted, true)+})+test('people enrichment authenticates in the header and keeps business fields in the body', () => {+ assert.equal(result(run(['people','enrich','--email','[email protected]'], `+ assert.equal(options.method, 'POST');+ assert.equal(parsed.pathname, '/api/v1/people/match');+ assert.equal(options.headers['x-api-key'], 'fixture-token');+ assert.deepEqual(body, {email:'[email protected]'});+ `)).accepted, true)+})+test('bulk and organization search keep their POST payloads and header authentication', () => {+ result(run(['people','bulk-enrich','--emails','[email protected],[email protected]'], `+ assert.equal(options.method, 'POST');+ assert.equal(options.headers['x-api-key'], 'fixture-token');+ assert.deepEqual(body, {details:[{email:'[email protected]'},{email:'[email protected]'}]});+ `))+ result(run(['organizations','search','--locations','New York'], `+ assert.equal(options.method, 'POST');+ assert.equal(options.headers['x-api-key'], 'fixture-token');+ assert.deepEqual(body, {page:1,per_page:25,organization_locations:['New York']});+ `))+})+test('enrichment previews match the actual request and redact the key', () => {+ const p = result(run(['organizations','enrich','--domain','example.com','--dry-run'], "throw new Error('unexpected fetch')"))+ assert.equal(p.method, 'GET')+ assert.equal(new URL(p.url).searchParams.get('domain'), 'example.com')+ assert.equal(p.headers['x-api-key'], '***')+ assert.equal(p.body, undefined)+ assert.equal(JSON.stringify(p).includes('fixture-token'), false)+ const person = result(run(['people','enrich','--email','[email protected]','--dry-run'], "throw new Error('unexpected fetch')"))+ assert.equal(person.headers['x-api-key'], '***')+ assert.deepEqual(person.body, {email:'[email protected]'})+})diff --git a/tools/clis/apollo.js b/tools/clis/apollo.jsindex f3ce7d7..26ef373 100755--- a/tools/clis/apollo.js+++ b/tools/clis/apollo.js@@ -10,16 +10,16 @@ if ((!API_KEY) && rawArgs.length > 0) {}async function api(method, path, body) {- const authBody = body ? { ...body, api_key: API_KEY } : { api_key: API_KEY }if (args['dry-run']) {- return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'Content-Type': 'application/json' }, body: { ...authBody, api_key: '***' } }+ return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'Content-Type': 'application/json', 'x-api-key': '***' }, body: body || undefined }}const res = await fetch(`${BASE_URL}${path}`, {method,headers: {'Content-Type': 'application/json',+ 'x-api-key': API_KEY,},- body: JSON.stringify(authBody),+ body: body ? JSON.stringify(body) : undefined,})const text = await res.text()try {@@ -109,7 +109,8 @@ async function main() {case 'enrich': {const domain = args.domainif (!domain) { result = { error: '--domain required' }; break }- result = await api('POST', '/organizations/enrich', { domain })+ const params = new URLSearchParams({ domain })+ result = await api('GET', `/organizations/enrich?${params}`)break}default:diff --git a/tools/integrations/apollo.md b/tools/integrations/apollo.mdindex 0623d65..1c38b48 100644--- a/tools/integrations/apollo.md+++ b/tools/integrations/apollo.md@@ -72,13 +72,16 @@ POST https://api.apollo.io/api/v1/mixed_companies/search### Organization Enrichment```bash-POST https://api.apollo.io/api/v1/organizations/enrich+GET https://api.apollo.io/api/v1/organizations/enrich?domain=apollo.io-{- "domain": "apollo.io"-}+x-api-key: {api_key}```+Organization enrichment uses a query parameter and has no request body.+API keys belong in the `x-api-key` header for every request. See the official+[authentication](https://docs.apollo.io/reference/authentication) and+[organization enrichment](https://docs.apollo.io/reference/organization-enrichment) references.+## Key Metrics### Person Data