{
    "openapi": "3.1.0",
    "info": {
        "title": "CLEANPANELS Platform API",
        "version": "1.0",
        "description": "WhatsApp numbers, email domains and mailboxes, wallet. Panel (SMM v2) API: see https://cleanpanels.co.ke/developers#panel-api"
    },
    "servers": [
        {
            "url": "https://cleanpanels.co.ke/api/v1"
        }
    ],
    "components": {
        "securitySchemes": {
            "bearer": {
                "type": "http",
                "scheme": "bearer"
            }
        }
    },
    "security": [
        {
            "bearer": []
        }
    ],
    "paths": {
        "/me": {
            "get": {
                "tags": [
                    "Account"
                ],
                "summary": "Who am I",
                "description": "Your account, pricing tier and wallet balance. Good first call to test your key.",
                "operationId": "a_me",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "name": "Jane",
                                    "email": "jane@example.com",
                                    "tier": "external",
                                    "wallet": {
                                        "balance": 25.5,
                                        "currency": "USD"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/wallet": {
            "get": {
                "tags": [
                    "Account"
                ],
                "summary": "Wallet and transactions",
                "description": "Balance and your last 50 wallet transactions. Services are paid monthly from this wallet.",
                "operationId": "a_wallet",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "balance": 25.5,
                                    "currency": "USD",
                                    "transactions": [
                                        {
                                            "id": 901,
                                            "amount": -5,
                                            "balance_after": 25.5,
                                            "type": "charge",
                                            "description": "WhatsApp API number — first month",
                                            "created_at": "2026-10-25T09:12:00+03:00"
                                        }
                                    ],
                                    "top_up_url": "https://cleanpanels.co.ke/wallet"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/prices": {
            "get": {
                "tags": [
                    "Account"
                ],
                "summary": "Your prices",
                "description": "What you pay per month, including any custom reseller pricing.",
                "operationId": "a_prices",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "tier": "reseller",
                                    "currency": "USD",
                                    "custom_pricing": false,
                                    "monthly": {
                                        "whatsapp_number": 4,
                                        "mailbox": 1.5
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/whatsapp/instances": {
            "post": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Create a WhatsApp number",
                "description": "Starts a new number (first month charged from your wallet) and returns a QR code. Scan it in WhatsApp → Linked devices.",
                "operationId": "w_create",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Support",
                                    "status": "pending",
                                    "webhook_secret": "whsec_…",
                                    "connection": {
                                        "status": "qr",
                                        "qr": "data:image/png;base64,…"
                                    }
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "example": "Support"
                                    },
                                    "webhook_url": {
                                        "type": "string",
                                        "example": "https://yourapp.com/whatsapp-webhook"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "get": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "List numbers",
                "description": "All your WhatsApp numbers with status and message counts.",
                "operationId": "w_list",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": [
                                        {
                                            "id": 12,
                                            "name": "Support",
                                            "status": "connected",
                                            "phone": "254712345678",
                                            "messages_in": 120,
                                            "messages_out": 96
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/whatsapp/instances/{id}/qr": {
            "get": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Connection status / QR",
                "description": "Poll every few seconds while linking: returns a fresh QR until status becomes \"connected\".",
                "operationId": "w_qr",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "status": "connected",
                                    "phone": "254712345678"
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/whatsapp/instances/{id}/send": {
            "post": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Send a message",
                "description": "\"to\" is a phone number in international format (digits only) OR a group ID (JID) ending in @g.us from GET …/groups. In groups you can @mention people: add \"mentions\": [\"254711111111\"] and write \"@254711111111\" in the text. The number must be a member of the group (and an admin if only admins can send).",
                "operationId": "w_send",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "sent": true,
                                    "to": "254712345678",
                                    "group": false,
                                    "message_id": "3EB0C4A1F2"
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "to": {
                                        "type": "string",
                                        "example": "254712345678"
                                    },
                                    "text": {
                                        "type": "string",
                                        "example": "Your order #20481 is complete ✅"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/whatsapp/instances/{id}/media": {
            "post": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Upload a file to send",
                "description": "Upload once, send many times with \"media_id\" (kept 3 days). Send a multipart form with a \"file\" field (up to 25 MB) or JSON with media_url / media_base64; \"type\" is optional (we detect it). GET …/media/{media_id} shows a file, DELETE removes it.",
                "operationId": "w_media",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "media_id": "9f2c…",
                                    "type": "image",
                                    "mimetype": "image/jpeg",
                                    "filename": "promo.jpg",
                                    "size": 182311,
                                    "url": "https://cleanpanels.co.ke/wa-media/9f2c…",
                                    "expires_at": "2026-12-01T10:00:00+00:00"
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "media_url": {
                                        "type": "string",
                                        "example": "https://yourshop.com/promo.jpg"
                                    },
                                    "type": {
                                        "type": "string",
                                        "example": "image"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/whatsapp/instances/{id}/groups": {
            "get": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "List groups",
                "description": "Groups this number is a member of. \"id\" is the group JID to send to. can_send=false means only admins may post there. Cached for 2 minutes; add ?refresh=1 after joining a new group.",
                "operationId": "w_groups",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": [
                                        {
                                            "id": "120363025246125486@g.us",
                                            "name": "VIP Customers",
                                            "participants": 148,
                                            "is_admin": true,
                                            "admins_only": false,
                                            "can_send": true
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/whatsapp/instances/{id}": {
            "patch": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Change settings",
                "description": "Change name, webhook_url or respond_groups.",
                "operationId": "w_update",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 12,
                                    "name": "Support",
                                    "webhook_url": "https://yourapp.com/new-webhook",
                                    "respond_groups": false
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "webhook_url": {
                                        "type": "string",
                                        "example": "https://yourapp.com/new-webhook"
                                    },
                                    "respond_groups": {
                                        "type": "boolean",
                                        "example": false
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Unlink / delete",
                "description": "Deletes the number and stops billing. Use POST …/12/logout to only unlink the phone.",
                "operationId": "w_logout",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "deleted": true
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/whatsapp/instances/{id}/messages": {
            "get": {
                "tags": [
                    "WhatsApp"
                ],
                "summary": "Recent messages",
                "description": "The last 100 messages in and out.",
                "operationId": "w_messages",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": [
                                        {
                                            "direction": "in",
                                            "peer": "254712345678",
                                            "text": "20481 status",
                                            "status": "received",
                                            "created_at": "2026-10-25T10:01:00+03:00"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/email/domains": {
            "post": {
                "tags": [
                    "Email"
                ],
                "summary": "Add an email domain",
                "description": "Creates the domain and its DKIM key (ready in about a minute). Returns the DNS records to publish.",
                "operationId": "e_domain",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "domain": "brandx.com",
                                    "status": "provisioning",
                                    "dns_records": [
                                        {
                                            "type": "TXT",
                                            "name": "brandx.com",
                                            "value": "v=spf1 a mx ip4:… ~all"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "domain": {
                                        "type": "string",
                                        "example": "brandx.com"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/email/domains/{id}/cloudflare": {
            "post": {
                "tags": [
                    "Email"
                ],
                "summary": "One-click DNS with Cloudflare",
                "description": "Your customer's Cloudflare token (template \"Edit zone DNS\") — used once, never stored. Merges SPF, adds DKIM and DMARC, and MX only if receive_mail is true.",
                "operationId": "e_cloudflare",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "cloudflare": {
                                        "zone": "brandx.com",
                                        "changes": [
                                            "Updated your SPF record to include our server",
                                            "Added DKIM record",
                                            "Added DMARC record",
                                            "Added MX record — email to brandx.com now arrives here"
                                        ]
                                    },
                                    "can_send": true,
                                    "can_receive": true
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "api_token": {
                                        "type": "string",
                                        "example": "CLOUDFLARE_TOKEN"
                                    },
                                    "receive_mail": {
                                        "type": "boolean",
                                        "example": true
                                    },
                                    "replace_mx": {
                                        "type": "boolean",
                                        "example": false
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/email/domains/{id}/dns": {
            "get": {
                "tags": [
                    "Email"
                ],
                "summary": "Live DNS check",
                "description": "Checks every record against public DNS. Each has status ok | missing | wrong | warn | info, what was found, and a fix.",
                "operationId": "e_dns",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "summary": {
                                        "can_send": false,
                                        "can_receive": false,
                                        "inbox_ready": false,
                                        "records": {
                                            "spf": "wrong",
                                            "dkim": "ok",
                                            "dmarc": "warn",
                                            "mx": "info"
                                        }
                                    },
                                    "dns_check": [
                                        {
                                            "key": "spf",
                                            "status": "wrong",
                                            "message": "Your SPF record does not include our server yet. Replace it with:",
                                            "suggest": "v=spf1 ip4:… include:_spf.google.com ~all"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/email/mailboxes": {
            "post": {
                "tags": [
                    "Email"
                ],
                "summary": "Create a mailbox",
                "description": "On your verified domain (domain_id) or the shared domain (\"domain\":\"shared\"). The password is shown only once.",
                "operationId": "e_mailbox",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 7,
                                    "address": "support@brandx.com",
                                    "status": "provisioning",
                                    "smtp": {
                                        "host": "mail.cleanpanels.co.ke",
                                        "port_ssl": 465,
                                        "port_tls": 587,
                                        "username": "support@brandx.com",
                                        "password": "…",
                                        "imap_host": "mail.cleanpanels.co.ke",
                                        "imap_port": 993
                                    }
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "domain_id": {
                                        "type": "integer",
                                        "example": 42
                                    },
                                    "name": {
                                        "type": "string",
                                        "example": "support"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/email/mailboxes/{id}": {
            "patch": {
                "tags": [
                    "Email"
                ],
                "summary": "Forwarding, auto-reply, aliases, size",
                "description": "Send only what you want to change. forward_to: up to 10 addresses ([] = off); keep_copy: false forwards without storing; aliases: extra addresses delivering to this mailbox; quota_mb: 512, 1024 or 2048; password: set your own (10+ letters and numbers). Live within a minute.",
                "operationId": "e_settings",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 7,
                                    "address": "support@brandx.com",
                                    "status": "active",
                                    "settings": {
                                        "forward_to": [
                                            "owner@gmail.com"
                                        ],
                                        "keep_copy": true,
                                        "autoreply": {
                                            "enabled": true,
                                            "message": "Thanks! We reply within 24 hours."
                                        },
                                        "aliases": [
                                            "sales@brandx.com",
                                            "hello@brandx.com"
                                        ],
                                        "quota_mb": 2048,
                                        "state": "syncing"
                                    },
                                    "changed": [
                                        "forwarding",
                                        "auto-reply",
                                        "aliases",
                                        "storage"
                                    ]
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "forward_to": {
                                        "type": "array",
                                        "example": [
                                            "owner@gmail.com"
                                        ]
                                    },
                                    "keep_copy": {
                                        "type": "boolean",
                                        "example": true
                                    },
                                    "autoreply": {
                                        "type": "object",
                                        "example": {
                                            "enabled": true,
                                            "message": "Thanks! We reply within 24 hours."
                                        }
                                    },
                                    "aliases": {
                                        "type": "array",
                                        "example": [
                                            "sales",
                                            "hello"
                                        ]
                                    },
                                    "quota_mb": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/email/domains/{id}": {
            "patch": {
                "tags": [
                    "Email"
                ],
                "summary": "Catch-all for a domain",
                "description": "Mail to any address @domain that does not exist is delivered here instead of bouncing. Send null to turn it off.",
                "operationId": "e_catchall",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "id": 42,
                                    "domain": "brandx.com",
                                    "status": "active",
                                    "catchall": "support@brandx.com",
                                    "can_send": true,
                                    "can_receive": true
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "catchall": {
                                        "type": "string",
                                        "example": "support@brandx.com"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/email/mailboxes/{id}/reset-password": {
            "post": {
                "tags": [
                    "Email"
                ],
                "summary": "New mailbox password",
                "description": "Generates a new password (takes effect within a minute).",
                "operationId": "e_reset",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "example": {
                                    "password": "…",
                                    "note": "Takes effect within a minute."
                                }
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        }
    }
}