# PayBot API Control every merchant area through REST or MCP: products and discounts, Discord roles/channels, courses/PDFs, pages/payment links, live events, customers/gifts, promotions, onboarding, automations, reviews, affiliates/revenue, reports/tracking, settings, billing, partner and support. Platform-operator administration is excluded. ## Connect Base URL: https://go.paybotapp.com/api/v1 MCP: POST https://go.paybotapp.com/api/v1/mcp Reference: GET https://go.paybotapp.com/api/v1/openapi.json The merchant opens the dashboard's API & Agents sidebar tab → Create a key, chooses a name, permissions and expiry, then clicks Create API key. Presets: - Read only: inspect existing resources; cannot change settings or send messages. - Configure PayBot: build products, channels, courses and pages; includes publishing promotions and configuring automations, but excludes refunds, access removal, resource deletion and account management. - Courses only: course authoring plus compatibility with original course clients. - Full merchant control: includes sensitive financial, messaging, deletion and account actions. Use only when the merchant explicitly requests those powers. Choose the least access needed. The key is shown once; Copy key, store it in the agent client's secret settings or a local gitignored environment file, then choose I saved it. Do not ask the merchant to paste the key into chat. If the client's connection steps are unknown, ask which client they use instead of guessing. Send Authorization: Bearer on every call. Store the key as a secret, never in source, public pages, shared prompts or logs. One key belongs to one server and one administrator. Expired/revoked keys and lost administrator authority stop work. Human key management is intentionally absent from the agent API. The same section has Copy agent setup. Its prompt asks the agent to learn the merchant's intended business, guide missing decisions, inspect current state and complete the requested setup across all relevant areas. Courses only is available for a narrow course-building credential; existing integrations retain their keys. ## Agent setup flow 1. GET /me to verify your key and server. GET /capabilities to inspect grants and feature availability. Do not guess IDs or assume a plan enables a feature. If /me reports only the legacy courses scope, follow its /courses next step and the course reference below. Ask for a broader key for other merchant work. 2. GET /setup/status to see Stripe readiness, installation and unresolved setup. 3. GET /operations/catalog?area=products (or another area) for named operations, exact URLs, JSON schemas, query parameters and required scopes. The full catalog is available without a filter. It includes unavailable grants with reasons. 4. Read existing resources. Reuse their IDs and latest versions. Preserve unrelated settings. A replacement course document must retain lesson slugs and content. 5. Perform only the merchant's requested changes. Every catalogued merchant JSON mutation requires an 8–200 character unique idempotency_key in its body AND the identical Idempotency-Key header. Keep the key and exact payload until the result is known. Legacy /courses routes below retain their original per-endpoint contract; their new private drafts use client_request_id, not this receipt contract. 6. A 202, operation_pending, pending_operations or operation ID is acceptance, not completion. GET /operations/{operation_id} until succeeded/failed. For event schedules, inspect the event occurrence; scheduled is not live. Saved automations and scheduled publications remain configuration until explicitly changed. 7. Report completed changes, scheduled work, failed operations and human handoffs separately. Never report success merely because a command was accepted. MCP clients use paybot_capabilities and paybot_setup_status, then paybot_find_operations → paybot_describe_operation → paybot_call. Discovery is progressive so all features are available without dumping every schema into context. paybot_call accepts {operation, path, query, body}; path contains only resource IDs named by the described operation. The server inserts the credential's guild ID. ## Feature map Catalog areas: setup, products, discord, courses, pages, events, customers, promotions, onboarding, automations, reviews, affiliates, analytics, reports, settings, billing, partner, support, operations. - Products: create/edit/archive/restore, groups, Stripe import/copy, prices, discounts, intro offers, access, sales rounds/spots and upgrade credit. Read the product's version before changing it. Price changes retain existing buyer rules. A one-off charge for one buyer is a one-time product created with single_use=true: link-only, one payment, then archived automatically. Send the buyer its payment link (portal + payment_link_code, as for any link-only product); on edit, sale_plan.single_use keeps or ends it. Only when the merchant says they sell from their own website, set website_checkout=true and give them the payment link plus /go for that website's buy button. Every other share uses the normal payment link. To stop new buyers without ending anything, set sales_off=true on the product; it works on every kind of product, including a live Event, and sales_off=false starts selling again. Archive only a product that is finished for good. - Discord: inventory and typed resource operations. Create or attach roles and channels, then inspect the operation result. Only PayBot-supported resource management is available; this is not an arbitrary Discord proxy. - Courses: private drafts, document replacement, preview/review/publish/scheduling, sale/access products, server settings and course cards. Upload PDFs with the existing raw-binary /courses/files endpoint, then use file_id in a PDF block. A merchant key needs courses:write for uploads or courses:read for previews. - Pages: read studio_pages for portal IDs, tier codes, settings and current content. Page editing operations live under /guilds/{guild_id}/pages. The tier field is a payment-link code, not a product ID. The portal block id comes from the read. - Events: use paid_event_read/start/cancel_start/end/end_time/access/promo. A live-show product and its current occurrence are different objects. Start schedules when starts_in_minutes is nonzero, or at starts_at (ISO time with zone, up to 60 days ahead; buyers can pay until then). Optional ends_at ends it automatically, and reminder_minutes (0, 10, 30, 60, 120, 1440) repost the purchase card in promo_channel_id before the start. Ending by hand requires the handler's explicit confirmation. paid_event_end_time changes a scheduled or live show's end (ends_at ISO time with zone, after now and within 7 days of the start; null means it runs until ended by hand); nobody is charged again. A ticket bought while no show is scheduled waits for a show the buyer attends, whatever event_no_show_policy says. A product's event_role_ids (up to 10 existing roles) are given to buyers while a show is live and taken back after. - Customers: use customers/gifts reads and customer_action with the supported action enum. Never infer a refund, cancellation or access removal from vague setup instructions. The key must explicitly grant its financial/access effects. To show staff who is subscribed, settings_operation post_subscriber_list posts one product's active subscribers into a channel the merchant names. Chargebacks: disputes lists them; dispute_evidence previews what PayBot prepared; fill_dispute_evidence saves it, with its receipt, customer signature and customer communication PDFs, onto the Stripe dispute without submitting, and never overwrites what the merchant saved. PayBot never submits: the merchant adds their own proof and submits in Stripe, and gets one chance to answer a dispute. dispute_risk says what to act on first: payments Stripe flagged as fraud (refund_flagged_payment, only on the merchant's go-ahead, usually prevents the dispute; dismiss_flagged_payment when they know the buyer), disputes awaiting an answer, buyers who disputed and can still dispute more (stop_disputing_buyer cancels and refunds those, only on the merchant's go-ahead; the disputed payment is never touched), and the 30-day dispute rate. A stolen-card refund blocks that buyer from buying here (customers show blocked: true); lift_buyer_block undoes it, only on the merchant's word. update_chargeback_settings turns on card verification at checkout and removing access when a payment is flagged, and (on by default) warn_risky_joins, a reports-channel card when someone with a stolen card or recent chargeback on another server joins; set them only as the merchant asks. - Analytics: studio_analytics `events` are dated changes for the chart (a marker shows timing, not cause). add_analytics_note / delete_analytics_note manage the merchant's own notes, only as the merchant asks. - Promotions/onboarding/automations/reviews: configuring a post or message can authorize future sends. Preview first when available. Tests and invite operations send real messages and require messages:send. Configure only requested recipients. update_onboarding_delivery sends a product's welcome as a DM or in a private thread with the buyer and a staff role (25 people at most); the bot refuses a channel buyers or staff cannot see, so wait for the operation and read back. - Support (only on servers it is enabled for): settings_operation create_support_channel turns the buyer support agent on, and needs a reports channel. update_settings section support turns it off or saves support_notes. add_support_source and remove_support_source manage the documents it searches (page, text or file); list_support_site_pages finds a website's pages to choose from. Read support_agent to confirm. All need messages:send, because they decide what buyers are told. - Affiliates/revenue/settings: preserve section versions and current settings. Financial sharing needs money:write and account:manage. Settings section schemas describe the applicable fields; unrelated section fields are rejected. - Billing/partner/support: the merchant's supported account actions are included. The billing read includes account-control links and therefore requires both billing:read and account:manage. A Read only key can still inspect Stripe readiness through /setup/status; defer account controls instead of escalating silently. Connect Stripe or install/reauthorize Discord via GET /handoffs/stripe or /handoffs/discord; return requires_user_action to the person, then resume using /setup/status. An API key cannot substitute for external provider consent. ## Permissions and limits Keys contain explicit area:read and area:write grants. Sensitive effects also need messages:send, money:write, access:remove, resources:delete or account:manage. Some combined commands require several grants; 403 names missing grants before any write. Presets are copied at issuance, never silently expanded. Existing courses keys stay course-only and continue to work with the legacy reference below. Shared feature flags, plans, owner-only actions, Discord permissions and resource ownership rules apply equally to the API and dashboard. JSON bodies are limited to 1 MiB. Server-wide limits are 120 API calls/minute and 30 mutations/minute, with 200 mutations/server/day and 2,000 globally/day. Adding keys cannot multiply allowances. PDF uploads retain their own storage, size and attempt limits. Use sequential writes for dependent objects; retries are not a reason to create more keys. ## Recovery - 401: key missing, revoked or expired. Ask the merchant for a valid credential. - 403: wrong server, missing grant or lost human authority. Do not try another route, cookie, or fabricated owner flag to bypass it. - 409 version conflict: read current state and review changes before a new command. - 409 idempotency_conflict: the key was reused with different input. Inspect the original operation; never blindly retry it with a fresh key. - 409 outcome_pending: inspect GET /requests/{request_id}, the target resource and queued operations. The command may have committed before a connection failed. Pending receipts never automatically execute again. - 422: correct the documented input. Keep a distinct key for a corrected command. - 429: wait the Retry-After delay; avoid concurrent retry storms. - A completed refused receipt is saved too. If a refusal is replayed, inspect current state and address its cause before submitting a new command/key. - 503/network timeout: retry identical input with the original idempotency key. X-Request-Id identifies the receipt. Receipt completion means the HTTP command returned, while any queued operation still needs its own completion check. API-issued bot commands are reauthorized before execution. Revocation prevents pending commands from starting. Already committed settings, running events and domain reconciliation remain valid merchant state; revoke is not an undo command. ## Legacy course-only integration reference The following endpoints preserve the original course document API. New merchant keys use the guild-scoped course operations above for granular read/write access. The PDF upload and preview endpoints accept both credential types. # PayBot Courses API > PayBot lets a Discord community sell access to courses. This HTTP API lets a > merchant's own agent build those courses programmatically — courses are large, > tedious work, so you (the agent) assemble the whole thing in one request instead > of clicking through Discord. One POST creates a course with all its modules, > content blocks, completion reward, prerequisites, and unlocks. ## Base URL ``` https://go.paybotapp.com/api/v1 ``` ## Authentication Every request needs a per-guild API key in the `Authorization` header: ``` Authorization: Bearer pbk_live_xxxxxxxxxxxxxxxxxxxx ``` Create keys in the dashboard's **API & Agents** sidebar tab. Choose **Courses only** for a course-only client. Existing Discord-issued keys still work. A key is scoped to one Discord server — it can only read and write that server's courses. The server is derived from the key, never from the request, so you never send a guild/server id. Verify a key before doing anything else: ``` GET /api/v1/me → 200 { "guild_id": "1009912742695669770", "scopes": ["courses"] } ``` ## Endpoints | Method | Path | Purpose | |--------|------|---------| | `GET` | `/me` | Verify the key; returns its guild + scopes. | | `GET` | `/courses` | List this server's courses (brief). | | `POST` | `/courses/files?filename=lesson.pdf` | Upload raw PDF bytes with Content-Type: application/pdf and Content-Length; returns file_id, filename, size_bytes (201). | | `GET` | `/courses/files/{file_id}` | Read same-server file metadata and a five-minute download_url for author preview. | | `GET` | `/courses/{course_code}` | Fetch one course as a full document. | | `POST` | `/courses/drafts` | Save a private draft. New drafts require client_request_id; existing drafts require course_code and updated_at. | | `GET` | `/courses/{course_code}/draft` | Fetch the working draft and its version, published state, and conflict state. | | `POST` | `/courses/preview` | Privately render {document, lesson: null or index, audience: eligible/visitor/locked}; returns HTML and warnings without side effects. | | `POST` | `/courses/{course_code}/publish` | Explicitly publish {updated_at, visibility: published/unlisted} from the reviewed draft. | | `POST` | `/courses` | Legacy immediate creation. Explicit published visibility makes content live. Prefer private drafts for imports. | | `PUT` | `/courses/{course_code}` | Explicit live replacement. Requires updated_at from the latest published GET. | | `DELETE` | `/courses/{course_code}` | Delete a course (cascades to modules, blocks, unlocks, enrollments). `204`. | For authoring, fetch the private draft, preserve lesson slugs and updated_at, edit the document, then POST /courses/drafts. For a new draft omit course_code and send a unique client_request_id; reuse it only when retrying that same create. Review preview warnings and show the creator any lessons the import removes. Publish only after the creator approves the content and intended audience. On 409 preserve your proposed text, fetch both latest draft and published course, and resolve the conflict. Never retry a stale whole-document replacement blindly. ## The course document `POST /courses` takes one JSON object describing the whole course: ```jsonc { "name": "Intro to Candlestick Charts", // required "description": "A 4-module primer for new traders.", "cover_image_url": "https://example.com/cover.png", "visibility": "draft", // "draft" | "published" | "unlisted" "access_mode": "public", // "public" | "guild_members"; "paid" is dashboard-created and may only be round-tripped "sequential_module_lock": false, // true = modules unlock in order "discussion_enabled": false, // true = auto-create a Discord forum for the course "completion": { // reward when a learner finishes "role_id": "123456789012345678", // Discord role granted on completion (optional) "suffix": "📈 Chartist", // appended to their nickname (optional) "public_feed_post": true // announce completion in the public feed }, "prerequisites": ["aBcD1234"], // course_codes (same server) that must be completed first "unlocks": [ // extra things completion grants { "target_type": "channel", "target_id": "222333444555666777" }, { "target_type": "role", "target_id": "888999000111222333" } ], "modules": [ { "name": "What is a candle?", // required "subtitle": "Open, high, low, close.", "module_slug": "what-is-a-candle", // optional stable id; derived from name if omitted "estimated_time_minutes": 8, // shown to learners as a time estimate "blocks": [ { "block_type": "heading", "content": { "text": "Anatomy of a candle" } }, { "block_type": "paragraph", "content": { "text": "Each candle encodes four prices..." } }, { "block_type": "video_embed", "content": { "url": "https://youtube.com/watch?v=abc" } } ] } ] } ``` Only `name` is strictly required; everything else has sensible defaults. A course created `draft` is invisible to learners until you set `visibility: "published"`. ### Block types Each module is an ordered list of `blocks`. `block_type` + its `content` object: | `block_type` | `content` shape | |--------------|-----------------| | `heading` | `{ "text": "..." }` | | `pdf` | `{ "file_id": "", "title": "Lesson PDF" }` — upload first; never store the expiring download_url | | `paragraph` | `{ "text": "..." }` | | `video_embed` | `{ "url": "https://..." }` | | `image` | `{ "url": "https://...", "alt": "...", "caption": "..." }` — `alt`/`caption` optional | | `external_link` | `{ "url": "https://...", "title": "...", "subtitle": "..." }` — `title`/`subtitle` optional | | `resource_list` | `{ "title": "...", "items": [ { "title": "...", "url": "https://..." } ] }` — ≥1 item, each needs `url` | | `discussion_cta` | `{}` — links to the module's auto-created forum post (requires `discussion_enabled: true`) | | `checklist` | `{ "title": "Milestones", "items": [ { "id": "weigh-in", "text": "Record your **starting weight**", "input": "Starting weight (lbs)" } ] }` — `title` and `input` optional; 1-50 items; `id` is 1-64 letters, numbers, `-` or `_`, unique within the module. Learners tick items on the lesson page; their ticks are stored by `id`, so keep each item's `id` from GET when you reword it (a new `id` starts that item unticked). `input` adds a short text field the learner fills in. Ticking items does not complete the module. | All URLs must be `http(s)`. `javascript:`/`data:` URLs are rejected. Descriptions and paragraph text support Markdown: **bold**, *italic*, bullet and numbered lists, [label](https://example.com), and __underline__. Double underscores mean underline (Discord convention); use double asterisks for bold. Single newlines stay visible. Raw HTML and Markdown images remain literal; use Image/Video blocks. Formatted source must retain its actual formatting markers; do not invent missing underlines or emphasis during import. ### Unlock target types `unlocks[].target_type` is one of `role`, `channel`, `thread`, `forum_thread`; `target_id` is the Discord snowflake id of that object. Channel unlocks are gated to the course's completion role, so set `completion.role_id` if you unlock channels. ## Limits ### Importing PDFs Upload each PDF sequentially to POST /courses/files?filename=. Send the file itself as the request body, not multipart, a URL, or base64. Include the usual Bearer key, Content-Type: application/pdf, and Content-Length. The key requires the courses scope; its server owns every resulting file. Use each returned file_id in a pdf block in your course document, normally one module per PDF. Name and order those modules, save a private draft, and follow the existing explicit publication workflow. Uploading alone does not create lessons or publish anything. API and dashboard uploads share the same quota. Limits: 25 MiB/file, 500 MiB/server, 100 uploads/server/day, 20 uploads/key/minute. A 429 requires backoff; upload sequentially. Invalid files return 415/422, oversized or missing-length uploads return 413, and full storage returns 409. Unattached files expire after seven days. Files referenced by saved drafts or published lessons are retained. GET /courses/files/{file_id} returns an author preview URL valid for 300 seconds; treat it as a temporary bearer link. Students should open the course lesson, where access is checked before file delivery. MCP course tools can save these pdf blocks too. Transfer binary PDF bytes through the REST upload endpoint using the same key; do not embed files in MCP JSON. These are abuse-prevention caps, not plan limits: | Limit | Value | |-------|-------| | Courses per server | 20 | | Modules per course | 25 | | Blocks per module | 50 | | Description characters | 20,000 | | Draft document | 1 MB | | Requests per key | 30 / minute | Over a cap → `409`. Over the rate limit → `429`. ## Errors | Status | Meaning | |--------|---------| | `401` | Missing / invalid / revoked API key | | `404` | No such course in this server | | `409` | Version conflict or cap exceeded; keep the proposed text and inspect the latest document | | `422` | Validation error (bad block content, unknown unlock type, unknown prerequisite) | | `429` | Rate limit exceeded | The whole document is validated *before* anything is written, so a `422`/`409` never leaves a half-built course behind. ## Worked example: private draft ```bash curl -X POST https://go.paybotapp.com/api/v1/courses/drafts \ -H "Authorization: Bearer pbk_live_xxxxxxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "client_request_id": "candlestick-draft-001", "name": "Intro to Candlestick Charts", "description": "A short primer for new traders.", "visibility": "draft", "modules": [ { "name": "What is a candle?", "estimated_time_minutes": 8, "blocks": [ { "block_type": "heading", "content": { "text": "Anatomy of a candle" } }, { "block_type": "paragraph", "content": { "text": "Each candle encodes four prices: open, high, low, close." } } ] } ] }' ``` The response is the created document, including the assigned `course_code`. The course is live at `https://go.paybotapp.com/c/{course_code}` once published. Saving this draft does not publish it. Review a private preview and obtain the creator's approval before calling the publish endpoint with its latest updated_at. For legacy immediate creation or explicit publication, Discord-side effects (forum channel when `discussion_enabled` is true, channel-permission gates for unlocks) are applied by the bot a moment later. ## MCP (for MCP-native agents) If your agent speaks the Model Context Protocol (Claude Desktop, Cursor, Claude Code, …), connect to the MCP server instead — the same operations are exposed as self-describing tools. Prefer `get_course_draft`, `save_course_draft`, `preview_course_draft`, then explicit `publish_course_draft`. Legacy `create_course` and `update_course` apply directly to learner-facing rows; `update_course` requires the latest published updated_at. `list_courses`, `get_course`, and `delete_course` remain available: ``` https://go.paybotapp.com/api/v1/mcp (Streamable HTTP transport) Authorization: Bearer pbk_live_… (same key) ``` Example MCP server config entry: ```jsonc { "mcpServers": { "paybot-courses": { "type": "http", "url": "https://go.paybotapp.com/api/v1/mcp", "headers": { "Authorization": "Bearer pbk_live_xxxxxxxxxxxxxxxx" } } } } ``` ## Machine-readable spec The OpenAPI 3 contract (REST) is at `https://go.paybotapp.com/api/v1/openapi.json`.