Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

fix(calendly): forward required user and group webhook scopes

Rudy Celeklib9092938ea06
diff --git a/tests/calendly-webhooks.test.cjs b/tests/calendly-webhooks.test.cjs
new file mode 100644
index 0000000..9e14aa2
--- /dev/null
+++ b/tests/calendly-webhooks.test.cjs
@@ -0,0 +1,42 @@
+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/calendly.js')
+const org = 'https://api.calendly.com/organizations/org'
+const user = 'https://api.calendly.com/users/user'
+const group = 'https://api.calendly.com/groups/group'
+function run(args, network = false) {
+ const code = `global.fetch = async (url, options) => {
+ if (!${network}) throw new Error('Unexpected request');
+ const query = new URL(url).searchParams;
+ if (query.get('scope') === 'user' && !query.get('user')) throw new Error('400 missing user');
+ return {status: 200, text: async () => JSON.stringify({ url, method: options.method, body: options.body ? JSON.parse(options.body) : null })};
+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`
+ return spawnSync(process.execPath, ['-e', code], {encoding:'utf8', env:{...process.env, CALENDLY_API_KEY:'test-only-key'}})
+}
+test('user-scoped list includes the requested user', () => {
+ const r = run(['webhooks', 'list', '--organization', org, '--scope', 'user', '--user', user], true)
+ assert.equal(r.status, 0, r.stderr)
+ assert.equal(new URL(JSON.parse(r.stdout).url).searchParams.get('user'), user)
+})
+test('group-scoped list and create forward the same group URI', () => {
+ for (const sub of ['list', 'create']) {
+ const r = run(['webhooks', sub, '--organization', org, '--scope', 'group', '--group', group, '--url', 'https://example.com/hook', '--events', 'invitee.created', '--dry-run'])
+ const preview = JSON.parse(r.stdout)
+ if (sub === 'list') assert.equal(new URL(preview.url).searchParams.get('group'), group)
+ else assert.equal(preview.body.group, group)
+ assert.equal(preview.headers.Authorization, '***')
+ }
+})
+for (const scope of ['user', 'group', 'invalid']) test(`invalid/incomplete ${scope} scope is rejected before fetch`, () => {
+ for (const sub of ['list', 'create']) {
+ const r = run(['webhooks', sub, '--organization', org, '--scope', scope, '--url', 'https://example.com/hook', '--events', 'invitee.created'])
+ assert.ok(JSON.parse(r.stdout).error)
+ }
+})
+test('default organization scope remains unchanged', () => {
+ const r = run(['webhooks', 'list', '--organization', org, '--dry-run'])
+ const p = new URL(JSON.parse(r.stdout).url).searchParams
+ assert.equal(p.get('scope'), 'organization'); assert.equal(p.get('organization'), org)
+})
diff --git a/tools/clis/calendly.js b/tools/clis/calendly.js
index d0bec15..c932eb5 100755
--- a/tools/clis/calendly.js
+++ b/tools/clis/calendly.js
@@ -182,10 +182,12 @@ async function main() {
const org = args.organization
const scope = args.scope || 'organization'
if (!org) { result = { error: '--organization URI required' }; break }
- const params = new URLSearchParams({
- organization: org,
- scope,
- })
+ if (!['organization', 'user', 'group'].includes(scope)) { result = { error: '--scope must be organization, user, or group' }; break }
+ if (scope === 'user' && !args.user) { result = { error: '--user URI required for user scope' }; break }
+ if (scope === 'group' && !args.group) { result = { error: '--group URI required for group scope' }; break }
+ const params = new URLSearchParams({ organization: org, scope })
+ if (args.user) params.set('user', args.user)
+ if (args.group) params.set('group', args.group)
params.set('count', String(count))
if (args['page-token']) params.set('page_token', args['page-token'])
result = await api('GET', `/webhook_subscriptions?${params}`)
@@ -197,8 +199,12 @@ async function main() {
const org = args.organization
const scope = args.scope || 'organization'
if (!url || !events || !org) { result = { error: '--url, --events (comma-separated), and --organization required' }; break }
+ if (!['organization', 'user', 'group'].includes(scope)) { result = { error: '--scope must be organization, user, or group' }; break }
+ if (scope === 'user' && !args.user) { result = { error: '--user URI required for user scope' }; break }
+ if (scope === 'group' && !args.group) { result = { error: '--group URI required for group scope' }; break }
const body = { url, events, organization: org, scope }
if (args.user) body.user = args.user
+ if (args.group) body.group = args.group
result = await api('POST', '/webhook_subscriptions', body)
break
}
@@ -239,7 +245,7 @@ async function main() {
availability: 'availability [times --event-type <uri> --start-time <iso> --end-time <iso> | busy --user <uri> --start-time <iso> --end-time <iso>]',
webhooks: 'webhooks [list --organization <uri> | create --url <url> --events <e1,e2> --organization <uri> | delete --uuid <id>]',
org: 'org [members --organization <uri>]',
- options: '--count <n> --page-token <token> --status <active|canceled>',
+ options: '--count <n> --page-token <token> --status <active|canceled> --scope <organization|user|group> --user <uri> --group <uri>',
}
}
}
diff --git a/tools/integrations/calendly.md b/tools/integrations/calendly.md
index d31e0d3..8f578a5 100644
--- a/tools/integrations/calendly.md
+++ b/tools/integrations/calendly.md
@@ -96,6 +96,12 @@ POST https://api.calendly.com/webhook_subscriptions
GET https://api.calendly.com/webhook_subscriptions?organization={organization_uri}&scope=organization
```
+For `scope=user`, include the `user` URI in the list query or creation body.
+For `scope=group`, include the `group` URI. The CLI forwards `--user` and
+`--group` and rejects these scopes when their identifier is missing.
+See [list subscriptions](https://developer.calendly.com/api-docs/calendly-api/webhooks/list-webhook-subscriptions)
+and [create subscription](https://developer.calendly.com/api-docs/calendly-api/webhooks/create-webhook-subscription).
+
### Delete webhook subscription
```bash