Skip to content

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

fix(tolt): align the integration with current public resources

Rudy Celekli4a5d42c5f090
diff --git a/tests/clis/tolt-public-api.test.cjs b/tests/clis/tolt-public-api.test.cjs
new file mode 100644
index 0000000..6bb4099
--- /dev/null
+++ b/tests/clis/tolt-public-api.test.cjs
@@ -0,0 +1,28 @@
+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/tolt.js')
+function run(args,oracle="throw new Error('unexpected fetch')") {
+ const code=`global.fetch=async(url,options)=>{const assert=require('node:assert/strict');const u=new URL(url);const body=options.body?JSON.parse(options.body):undefined;assert.equal(u.host,'api.tolt.com');assert.equal(options.headers.Authorization,'Bearer fixture-key');${oracle};return new Response(JSON.stringify({accepted:true}));};process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)});`
+ const r=spawnSync(process.execPath,['-e',code],{encoding:'utf8',timeout:10000,env:{...process.env,TOLT_API_KEY:'fixture-key'}});assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)
+}
+for(const group of ['partners','affiliates']) {
+ test(`${group} list sends required program scope and cursor`,()=>assert.equal(run([group,'list','--program-id','prg1','--starting-after','part+/=','--limit','25'],"assert.equal(u.pathname,'/v1/partners');assert.equal(u.searchParams.get('program_id'),'prg1');assert.equal(u.searchParams.get('starting_after'),'part+/=');assert.equal(u.searchParams.get('limit'),'25');").accepted,true))
+ test(`${group} get encodes positional ID`,()=>assert.equal(run([group,'get','part+/='],"assert.equal(u.pathname,'/v1/partners/part%2B%2F%3D');").accepted,true))
+ test(`${group} creation supplies required names and program`,()=>assert.equal(run([group,'create','--first-name','Jane','--last-name','Doe','--email','[email protected]','--program-id','prg1'],"assert.equal(options.method,'POST');assert.equal(u.pathname,'/v1/partners');assert.deepEqual(body,{first_name:'Jane',last_name:'Doe',email:'[email protected]',program_id:'prg1'});").accepted,true))
+ test(`${group} update uses PUT and nested payout details`,()=>assert.equal(run([group,'update','--id','part1','--payout-method','paypal','--paypal-email','[email protected]'],"assert.equal(options.method,'PUT');assert.equal(u.pathname,'/v1/partners/part1');assert.deepEqual(body,{payout_method:'paypal',payout_details:{email:'[email protected]'}});").accepted,true))
+}
+for(const group of ['customers','referrals']) {
+ test(`${group} list uses customer resources and partner filter`,()=>assert.equal(run([group,'list','--program-id','prg1','--affiliate-id','part1'],"assert.equal(u.pathname,'/v1/customers');assert.equal(u.searchParams.get('program_id'),'prg1');assert.equal(u.searchParams.get('partner_id'),'part1');assert.equal(u.searchParams.has('affiliate_id'),false);").accepted,true))
+}
+test('customer get requires the Tolt record ID',()=>assert.equal(run(['customers','get','--id','cust1'],"assert.equal(u.pathname,'/v1/customers/cust1');").accepted,true))
+test('commission list keeps program and partner scope',()=>assert.equal(run(['commissions','list','--program-id','prg1','--affiliate-id','part1'],"assert.equal(u.pathname,'/v1/commissions');assert.equal(u.searchParams.get('program_id'),'prg1');assert.equal(u.searchParams.get('partner_id'),'part1');").accepted,true))
+for(const group of ['partners','customers','commissions']) {
+ test(`${group} list rejects missing program before sending`,()=>assert.match(run([group,'list']).error,/program-id/))
+}
+test('unsupported commission-rate edit is explicit and offline',()=>assert.match(run(['affiliates','update','--id','part1','--commission-rate','30']).error,/commission-rate/))
+test('legacy customer lookup cannot silently confuse an external ID with a Tolt record',()=>assert.match(run(['referrals','get','--customer-id','stripe_customer1']).error,/Tolt.*--id/))
+test('undocumented payout history returns an actionable error',()=>assert.match(run(['payouts','list']).error,/dashboard/))
+test('creation rejects an incomplete name payload before sending',()=>assert.match(run(['partners','create','--program-id','prg1','--email','[email protected]','--name','Jane Doe']).error,/first-name.*last-name/))
+test('partner preview remains offline with the actual route and redacted credentials',()=>{const p=run(['partners','list','--program-id','prg1','--dry-run']);assert.equal(p.url,'https://api.tolt.com/v1/partners?program_id=prg1');assert.equal(p.headers.Authorization,'***')})
diff --git a/tools/clis/tolt.js b/tools/clis/tolt.js
index 29b3cf3..ed22252 100755
--- a/tools/clis/tolt.js
+++ b/tools/clis/tolt.js
@@ -2,7 +2,7 @@
const rawArgs = process.argv.slice(2)
const API_KEY = process.env.TOLT_API_KEY
-const BASE_URL = 'https://api.tolt.io/v1'
+const BASE_URL = 'https://api.tolt.com/v1'
if ((!API_KEY) && rawArgs.length > 0) {
console.error(JSON.stringify({ error: 'TOLT_API_KEY environment variable required' }))
@@ -52,99 +52,102 @@ function parseArgs(args) {
const args = parseArgs(rawArgs)
const [cmd, sub, ...rest] = args._
+function listParams() {
+ const params = new URLSearchParams({ program_id: args['program-id'] })
+ for (const [flag, field] of [['limit', 'limit'], ['starting-after', 'starting_after'], ['ending-before', 'ending_before']]) {
+ if (args[flag]) params.set(field, args[flag])
+ }
+ return params
+}
+
async function main() {
let result
-
+ const id = rest[0] || args.id
switch (cmd) {
+ case 'partners':
case 'affiliates':
switch (sub) {
- case 'list':
- result = await api('GET', '/affiliates')
- break
- case 'get': {
- const id = rest[0] || args.id
- if (!id) { result = { error: 'Affiliate ID required (positional arg or --id)' }; break }
- result = await api('GET', `/affiliates/${id}`)
+ case 'list': {
+ if (!args['program-id']) { result = { error: '--program-id required' }; break }
+ const params = listParams()
+ if (args.email) params.set('email', args.email)
+ result = await api('GET', `/partners?${params}`)
break
}
+ case 'get':
+ if (!id) { result = { error: 'Partner ID required (positional arg or --id)' }; break }
+ result = await api('GET', `/partners/${encodeURIComponent(id)}`)
+ break
case 'create': {
- const body = {}
- if (args.email) body.email = args.email
- if (args.name) body.name = args.name
- result = await api('POST', '/affiliates', body)
+ if (!args.email || !args['first-name'] || !args['last-name'] || !args['program-id']) {
+ result = { error: '--email, --first-name, --last-name, and --program-id required' }; break
+ }
+ const body = {
+ first_name: args['first-name'], last_name: args['last-name'],
+ email: args.email, program_id: args['program-id'],
+ }
+ result = await api('POST', '/partners', body)
break
}
case 'update': {
- if (!args.id) { result = { error: '--id required (affiliate ID)' }; break }
+ if (!id) { result = { error: '--id required (Tolt partner ID)' }; break }
+ if (args['commission-rate'] !== undefined) {
+ result = { error: '--commission-rate is not a documented partner update field; configure the program/group in the Tolt dashboard' }; break
+ }
const body = {}
- if (args['commission-rate']) body.commission_rate = Number(args['commission-rate'])
+ if (args['company-name']) body.company_name = args['company-name']
if (args['payout-method']) body.payout_method = args['payout-method']
- if (args['paypal-email']) body.paypal_email = args['paypal-email']
- result = await api('PATCH', `/affiliates/${args.id}`, body)
+ if (args['paypal-email']) body.payout_details = { email: args['paypal-email'] }
+ if (Object.keys(body).length === 0) { result = { error: 'Provide --company-name, --payout-method, or --paypal-email' }; break }
+ result = await api('PUT', `/partners/${encodeURIComponent(id)}`, body)
break
}
default:
- result = { error: 'Unknown affiliates subcommand. Use: list, get, create, update' }
+ result = { error: 'Unknown partners subcommand. Use: list, get, create, update' }
}
break
-
+ case 'customers':
case 'referrals':
switch (sub) {
case 'list': {
- const params = new URLSearchParams()
- if (args['affiliate-id']) params.set('affiliate_id', args['affiliate-id'])
- result = await api('GET', `/referrals?${params}`)
+ if (!args['program-id']) { result = { error: '--program-id required' }; break }
+ const params = listParams()
+ const partnerId = args['partner-id'] || args['affiliate-id']
+ if (partnerId) params.set('partner_id', partnerId)
+ result = await api('GET', `/customers?${params}`)
break
}
- case 'get': {
- const params = new URLSearchParams()
- if (args['customer-id']) params.set('customer_id', args['customer-id'])
- result = await api('GET', `/referrals?${params}`)
+ case 'get':
+ if (args['customer-id']) { result = { error: 'Use the Tolt customer record ID with --id; an external --customer-id is not a supported lookup' }; break }
+ if (!id) { result = { error: '--id required (Tolt customer record ID)' }; break }
+ result = await api('GET', `/customers/${encodeURIComponent(id)}`)
break
- }
default:
- result = { error: 'Unknown referrals subcommand. Use: list, get' }
+ result = { error: 'Unknown customers subcommand. Use: list, get' }
}
break
-
case 'commissions':
- switch (sub) {
- case 'list': {
- const params = new URLSearchParams()
- if (args['affiliate-id']) params.set('affiliate_id', args['affiliate-id'])
- result = await api('GET', `/commissions?${params}`)
- break
- }
- default:
- result = { error: 'Unknown commissions subcommand. Use: list' }
- }
+ if (sub !== 'list') { result = { error: 'Use: commissions list' }; break }
+ if (!args['program-id']) { result = { error: '--program-id required' }; break }
+ const params = listParams()
+ const partnerId = args['partner-id'] || args['affiliate-id']
+ if (partnerId) params.set('partner_id', partnerId)
+ result = await api('GET', `/commissions?${params}`)
break
-
case 'payouts':
- switch (sub) {
- case 'list': {
- const params = new URLSearchParams()
- if (args['affiliate-id']) params.set('affiliate_id', args['affiliate-id'])
- result = await api('GET', `/payouts?${params}`)
- break
- }
- default:
- result = { error: 'Unknown payouts subcommand. Use: list' }
- }
+ result = { error: 'Payout history is not documented in the current public API; use the Tolt dashboard' }
break
-
default:
result = {
error: 'Unknown command',
usage: {
- affiliates: 'affiliates [list|get|create|update] [id] [--email <email>] [--name <name>] [--id <id>] [--commission-rate <rate>] [--payout-method <method>] [--paypal-email <email>]',
- referrals: 'referrals [list|get] [--affiliate-id <id>] [--customer-id <id>]',
- commissions: 'commissions [list] [--affiliate-id <id>]',
- payouts: 'payouts [list] [--affiliate-id <id>]',
+ partners: 'partners (or affiliates) [list --program-id <id> | get <id> | create --email <email> --first-name <name> --last-name <name> --program-id <id> | update --id <id> [--company-name <name>] [--payout-method <method>] [--paypal-email <email>]]',
+ customers: 'customers (or referrals) [list --program-id <id> [--partner-id <id>] | get --id <Tolt_customer_id>]',
+ commissions: 'commissions list --program-id <id> [--partner-id <id>]',
+ options: '--limit <n> --starting-after <id> --ending-before <id> --dry-run',
}
}
}
-
console.log(JSON.stringify(result, null, 2))
}
diff --git a/tools/integrations/tolt.md b/tools/integrations/tolt.md
index 1e52afd..21813ca 100644
--- a/tools/integrations/tolt.md
+++ b/tools/integrations/tolt.md
@@ -6,9 +6,9 @@ Affiliate program management for SaaS, with Stripe and Paddle integration.
| Integration | Available | Notes |
|-------------|-----------|-------|
-| API | ✓ | REST API for affiliates, referrals, payouts |
+| API | ✓ | REST API for partners, customers, commissions |
| MCP | - | Not available |
-| CLI | - | Not available |
+| CLI | ✓ | [tolt.js](../clis/tolt.js) |
| SDK | - | JavaScript snippet for tracking |
## Authentication
@@ -17,66 +17,58 @@ Affiliate program management for SaaS, with Stripe and Paddle integration.
- **Header**: `Authorization: Bearer {api_key}`
- **Get key**: Settings > API in Tolt dashboard
-## Common Agent Operations
+## Current Public API
-### List affiliates
+The API base is `https://api.tolt.com/v1`, with `partners`, `customers`, and
+`commissions` resources. The CLI keeps `affiliates` as an alias for `partners`
+and `referrals` as an alias for `customers`.
-```bash
-GET https://api.tolt.io/v1/affiliates
-```
-
-### Get affiliate
+### List partners, customers, or commissions
```bash
-GET https://api.tolt.io/v1/affiliates/{affiliate_id}
+node tools/clis/tolt.js partners list --program-id prg_example
+node tools/clis/tolt.js customers list --program-id prg_example --partner-id part_example
+node tools/clis/tolt.js commissions list --program-id prg_example --partner-id part_example
```
-### Create affiliate
-
-```bash
-POST https://api.tolt.io/v1/affiliates
-
-{
- "email": "[email protected]",
- "name": "John Doe"
-}
-```
+These list operations require `program_id`. `--affiliate-id` remains an alias
+for the `--partner-id` filter. Use `--limit`, `--starting-after`, or
+`--ending-before` to page through results. Cursors are the returned record IDs.
-### List referrals
+### Create or update a partner
```bash
-GET https://api.tolt.io/v1/referrals?affiliate_id={affiliate_id}
+node tools/clis/tolt.js partners create --program-id prg_example --email [email protected] --first-name Jane --last-name Doe
+node tools/clis/tolt.js partners update --id part_example --payout-method paypal --paypal-email [email protected]
```
-### Get referral by customer
+Creation requires email, first name, last name, and program ID. Update uses
+`PUT /partners/{id}` and puts the payout email inside `payout_details`.
+Use explicit first/last names instead of the old ambiguous `--name` input.
-```bash
-GET https://api.tolt.io/v1/referrals?customer_id={stripe_customer_id}
-```
-
-### List commissions
+### Retrieve a record
```bash
-GET https://api.tolt.io/v1/commissions?affiliate_id={affiliate_id}
+node tools/clis/tolt.js partners get part_example
+node tools/clis/tolt.js customers get --id cust_example
```
-### Get payout history
+Customer retrieval uses the Tolt customer record ID, not an external billing
+customer ID. The old `--customer-id` lookup returns a migration error rather
+than silently treating a Stripe/customer reference as a Tolt record ID.
-```bash
-GET https://api.tolt.io/v1/payouts?affiliate_id={affiliate_id}
-```
+### Migration limits
-### Update affiliate
+The current public reference does not document payout-history retrieval or
+`commission_rate` as a partner update field. Those old commands/options return
+an actionable error directing users to the dashboard rather than issuing an
+undocumented request. `--dry-run` previews the request without sending it.
-```bash
-PATCH https://api.tolt.io/v1/affiliates/{affiliate_id}
-
-{
- "commission_rate": 30,
- "payout_method": "paypal",
- "paypal_email": "[email protected]"
-}
-```
+Primary contracts: [partners list](https://docs.tolt.com/partners/list),
+[create](https://docs.tolt.com/partners/create), [update](https://docs.tolt.com/partners/update),
+[customers list](https://docs.tolt.com/customers/list),
+[retrieve](https://docs.tolt.com/customers/retrieve), and
+[commissions list](https://docs.tolt.com/commissions/list).
## JavaScript Tracking