# Support tickets

Read the support tickets buyers open about your items, reply as you, close or reopen them, and keep internal notes — from your own helpdesk or an AI assistant. Replies follow the same rules as Workspace → Support: the buyer is notified, and the conversation stays in their Support inbox.

| Scope | Allows |
|---|---|
| `tickets:read` | List your tickets and read every message |
| `tickets:reply` | Reply to the buyer as you, close and reopen tickets |
| `tickets:note` | Add internal notes — only you see them, never the buyer |

`tickets:reply` and `tickets:note` are write permissions: they need a scoped token and come with the [Author API policy](https://sellmycode.net/api-docs/policy.md).

## Ticket states

| `state` | Meaning |
|---|---|
| `needs_reply` | Open, and the last message is from the buyer or an administrator — your turn |
| `waiting` | Open, and you answered last — waiting for the buyer |
| `closed` | Closed by you, the buyer or an administrator |

`waiting` is not something you set: replying puts the ticket there. Use `close: true` on a reply, or `PATCH`, to close it. Open tickets you answered close on their own after a few quiet days.

## List tickets

`GET /api/tickets`

| Parameter | Type | Description |
|---|---|---|
| `status` | string | `open` (default) \| `needs_reply` \| `waiting` \| `closed` \| `all` |
| `item_id` | integer | only tickets about this item |
| `per_page` | integer | default 25, max 50 |
```bash
curl "https://sellmycode.net/api/tickets?status=needs_reply" \
  -H "Authorization: Bearer $(cat ~/.config/sellmycode/token)"
```
```json
{
  "status": "success",
  "pagination": { "page": 1, "per_page": 25, "total": 2, "last_page": 1 },
  "tickets": [
    {
      "id": 812,
      "subject": "Webhook not firing after update",
      "item": { "id": 22314, "name": "Perfex Connect" },
      "buyer": "johndoe",
      "purchase": { "license_type": "Regular", "purchased_at": "2026-09-02T10:00:00Z",
                    "support_until": "2027-03-02T10:00:00Z", "support_active": true },
      "status": "open",
      "state": "needs_reply",
      "escalated": false,
      "closed_by_admin": false,
      "last_message": { "from": "buyer", "excerpt": "Since 1.1.0 the Zapier hook…", "at": "2026-10-24T08:12:00Z" },
      "created_at": "2026-10-24T08:12:00Z",
      "last_reply_at": "2026-10-24T08:12:00Z",
      "url": "https://sellmycode.net/workspace/support/…"
    }
  ]
}
```
## Read a ticket

`GET /api/tickets/{id}`

Every message in order. `from` is `buyer`, `author` or `admin`. Item support tickets do not carry attachments, so `attachments` is always empty. With `tickets:note` the answer also includes your internal `notes`.

```json
{
  "status": "success",
  "ticket": {
    "id": 812,
    "state": "needs_reply",
    "messages": [
      { "id": 5011, "from": "buyer", "username": "johndoe", "body": "Since 1.1.0 the Zapier hook…",
        "attachments": [], "created_at": "2026-10-24T08:12:00Z", "edited": false }
    ],
    "notes": [ { "id": 31, "body": "Known issue, fixed in 1.1.2", "token": "support-bot", "created_at": "2026-10-24T08:13:00Z" } ]
  }
}
```

## Reply

`POST /api/tickets/{id}/replies`

| Field | Type | Description |
|---|---|---|
| `body` *required* | string | Plain text, up to 10,000 characters — sent to the buyer as you |
| `close` | boolean | Reply and close the ticket in one go |
```bash
curl -X POST https://sellmycode.net/api/tickets/812/replies \
  -H "Authorization: Bearer $(cat ~/.config/sellmycode/token)" \
  -H "Content-Type: application/json" \
  -d '{"body":"Thanks! This is fixed in 1.1.2 — update from your Downloads page.","close":false}'
```
```json
{ "status": "success", "message": { "id": 5012, "created_at": "2026-10-24T08:14:00Z" },
  "ticket": { "id": 812, "state": "waiting", "…": "" } }
```
> **Warning:** One ticket accepts at most 10 replies per hour through the API (`reply_limit`) — a safety stop for a runaway bot. Let a person take over long conversations.

## Close or reopen

`PATCH /api/tickets/{id}`

| Field | Type | Description |
|---|---|---|
| `status` *required* | string | `closed` or `open` |

A ticket closed by an administrator stays closed (`closed_by_admin`), and a ticket closed more than 7 days ago cannot be reopened (`reopen_window`).

## Internal notes

`POST /api/tickets/{id}/notes`

| Field | Type | Description |
|---|---|---|
| `body` *required* | string | Up to 5,000 characters |

Notes appear in your Support inbox inside the ticket, marked "Internal note" with the token name — the buyer never sees them. Use them for an AI assistant's hand-over: what it found, what it suggests, why it did not answer.

## Get told about new messages

Subscribe a [webhook](https://sellmycode.net/api-docs/webhooks.md) to `ticket.created` and `ticket.replied`. They fire for buyer and administrator messages only — never for your own replies, so a bot cannot answer itself in a loop.

## Errors

| Code | HTTP | Meaning |
|---|---|---|
| `not_found` | 404 | No ticket with this id on your items |
| `ticket_closed` | 409 | Reopen the ticket before replying |
| `closed_by_admin` | 409 | Only an administrator can reopen it |
| `reopen_window` | 409 | Closed too long ago to reopen |
| `reply_limit` | 429 | 10 API replies on this ticket in the last hour |
| `validation` | 422 | A field is invalid — `errors` lists each one |

---
Source: https://sellmycode.net/api-docs/support-tickets
