@kody/kit
README.md
156 lines · 6.1 KB · Markdown@kody/kit
community-icon.svg is Kit's official wordmark from
kit.com/brand on Kit bright blue #44B1FF. Kit® is a
trademark of Kit. This package is not affiliated with or endorsed by Kit.
Intent
Reusable Kit (ConvertKit) helpers so Kody agents can list and update
the caller's subscribers, forms, tags, broadcast drafts, and sequences.
Reads are free-form. Mutations support dryRun: true and require
confirm: true. Broadcast helpers are draft-only and never send or
schedule.
This listing is meant to be forked. After you fork, connect your Kit account. No form ids, list names, sender addresses, or templates are baked in.
Share this package as https://kody.codes/@kody/kit
(never a /community/{listing_id} URL).
Agent setup
Kit has no built-in Kody OAuth app. Choose one lane:
| Lane | When to use | Credential |
|---|---|---|
| API key (recommended for personal automation) | Own-account scripts | User secret kitApiKey (or kitApiKey-<purpose>) sent as X-Kit-Api-Key |
| OAuth | Kit App Store apps, refresh tokens, multi-account | Saved integration kit or kit-<purpose> |
Required API host: api.kit.com. Approve it in the account secrets UI.
Saving a secret does not approve hosts by itself. Never paste keys into chat.
Lane A — v4 API key
- Create a v4 key at Developer settings
- Save it (do not paste the value in chat):
- Approve host
api.kit.com - Run the smoke test below
Lane B — BYO OAuth
- Create a Kit app and turn on API access: https://developers.kit.com/kit-app-store/building-apps#creating-your-app
- Set the redirect URI exactly to
https://kody.codes/connect/oauth - Connect while signed in to Kody:
- Paste the Kit client id and client secret into the Kody wizard (never into chat)
- Reconnect later with https://kody.codes/connect/oauth?provider=kit
OAuth authorize URL: https://api.kit.com/v4/oauth/authorize. Token URL:
https://api.kit.com/v4/oauth/token. Default scope is public.
To connect a second account, change provider (for example provider=kit-work)
and pass account: 'work' or integrationName: 'kit-work' / secretName: 'kitApiKey-work' on every call.
When To Use
- List, get, or upsert subscribers and manage tags
- List forms or add a subscriber to a form id the caller provides
- Create or update draft broadcasts (send from the Kit UI)
- Create sequences and enroll subscribers after confirmation
- Verify credentials with
./smoke-testbefore any write
Mutation safety
- Pass
dryRun: trueon writes to return{ dryRun: true, method, path, body }without contacting Kit. - Live writes throw unless
confirm: true. - Broadcast helpers refuse
send_atand send/publish statuses. There is no send-broadcast export. A human sends drafts from the returnededitUrl. - Form ids, tag names, sender addresses, and sequence names come from the call. This package has no default list, form, or template.
import { createBroadcastDraft } from 'kody:@kody/kit/broadcasts'
import { subscribeAndTag } from 'kody:@kody/kit/subscribers'
const draftPreview = await createBroadcastDraft({
subject: 'Workshop reminder',
content: '<p>See you tomorrow.</p>',
dryRun: true,
})
const signupPreview = await subscribeAndTag({
email_address: 'ada@example.com',
tagName: 'waitlist',
dryRun: true,
})A live draft after explicit user approval of the exact subject and body:
await createBroadcastDraft({
subject: 'Workshop reminder',
content: '<p>See you tomorrow.</p>',
confirm: true,
})Smoke test
./smoke-test is safe before anyone saves credentials: it returns
{ ok: true, live: false } and the setup URLs. After an API key or OAuth
connection and host approval, a static import reads the account and a few
broadcasts — it does not create subscribers or send email.
import kit from 'kody:@kody/kit'
export default async function main() {
return await kit({ action: 'smoke-test' })
}Exports
kody:@kody/kit— action dispatcher (defaults tosmoke-test); also re-exports every helperkody:@kody/kit/subscribers— list, get, create, update, unsubscribe, subscribe-and-tagkody:@kody/kit/tags— list, create, ensure, tag, untagkody:@kody/kit/forms— list forms, add subscriber to a form, list segmentskody:@kody/kit/broadcasts— list, get, draft create/update, delete, statskody:@kody/kit/sequences— list/create sequences and emails, enrollkody:@kody/kit/html— generic Liquid greeting and HTML blockskody:@kody/kit/account— account, email stats, growth statskody:@kody/kit/accounts— resolve integration/secret nameskody:@kody/kit/request— raw v4 path helperkody:@kody/kit/smoke-test— dry-run self-check, then a live readkody:@kody/kit/scheduled-account-health— no-arg weekly wrapper (jobaccount-healthis disabled by default)
Pass maxItems on list helpers. Without a cap, large accounts can exhaust
the execute timeout.
Jobs
account-health calls ./scheduled-account-health weekly (Monday 09:00 UTC).
It is enabled: false. Enabling it is an operator choice after you fork
and confirm the read is right for your account.
Errors
| Kit response | What to do |
|---|---|
| Missing credentials | Save kitApiKey or connect OAuth at the URLs above |
| 401 | Approve host api.kit.com and confirm the key or OAuth integration |
| 403 | Some bulk/purchase endpoints require OAuth, not an API key |
| Timeout on lists | Pass maxItems |