{
  "openapi": "3.1.0",
  "info": {
    "title": "Junco users' API",
    "version": "1",
    "summary": "Raise support tickets and read replies as one of a product's users.",
    "description": "What Junco's widget calls, for building your own support form (Unity, Godot, native apps, a server). Guides: https://desk.juncodesk.app/docs/api.md. Every error is JSON {\"error\": \"...\"} in words you can show the user. A user only ever sees their own tickets."
  },
  "servers": [
    {
      "url": "https://desk.juncodesk.app"
    }
  ],
  "paths": {
    "/v1/games/{publicKey}/tickets": {
      "parameters": [
        {
          "name": "publicKey",
          "in": "path",
          "required": true,
          "description": "The product's public key, jk_... (safe in client code).",
          "schema": {
            "type": "string",
            "pattern": "^jk_"
          }
        }
      ],
      "post": {
        "operationId": "createTicket",
        "summary": "Raise a ticket",
        "description": "JSON, or multipart/form-data with a \"ticket\" field holding the same JSON as text plus optional files: screenshot (PNG, JPEG or WebP, up to 2048 KB), save (up to 1024 KB), log (UTF-8 text, up to 512 KB). At most 3 files and 4096 KB a request. The AI starts on it at once; poll GET /tickets/{number} while aiWorking is true.",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewTicket"
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "ticket"
                ],
                "properties": {
                  "ticket": {
                    "type": "string",
                    "description": "The NewTicket object as JSON text."
                  },
                  "screenshot": {
                    "type": "string",
                    "format": "binary"
                  },
                  "save": {
                    "type": "string",
                    "format": "binary"
                  },
                  "log": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new ticket and its thread.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketDetail"
                }
              }
            }
          },
          "400": {
            "description": "A field is missing or wrong; the message names it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Too big: text, context or a file.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Not JSON or multipart, or a file of a type Junco doesn't take.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listTickets",
        "summary": "The user's tickets",
        "description": "Newest activity first, each with unread.",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "responses": {
          "200": {
            "description": "The tickets.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tickets"
                  ],
                  "properties": {
                    "tickets": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Ticket"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/games/{publicKey}/tickets/{number}": {
      "parameters": [
        {
          "name": "publicKey",
          "in": "path",
          "required": true,
          "description": "The product's public key, jk_... (safe in client code).",
          "schema": {
            "type": "string",
            "pattern": "^jk_"
          }
        },
        {
          "name": "number",
          "in": "path",
          "required": true,
          "description": "The ticket's number, as the API returned it.",
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "get": {
        "operationId": "getTicket",
        "summary": "One ticket and its messages",
        "description": "Marks the ticket read. Never includes the team's internal notes.",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "responses": {
          "200": {
            "description": "The ticket.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketDetail"
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/games/{publicKey}/tickets/{number}/messages": {
      "parameters": [
        {
          "name": "publicKey",
          "in": "path",
          "required": true,
          "description": "The product's public key, jk_... (safe in client code).",
          "schema": {
            "type": "string",
            "pattern": "^jk_"
          }
        },
        {
          "name": "number",
          "in": "path",
          "required": true,
          "description": "The ticket's number, as the API returned it.",
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "post": {
        "operationId": "reply",
        "summary": "The user replies",
        "description": "Reopens a resolved or released ticket.",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewReply"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The ticket with the new message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketDetail"
                }
              }
            }
          },
          "400": {
            "description": "Empty or too long.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/games/{publicKey}/unread": {
      "parameters": [
        {
          "name": "publicKey",
          "in": "path",
          "required": true,
          "description": "The product's public key, jk_... (safe in client code).",
          "schema": {
            "type": "string",
            "pattern": "^jk_"
          }
        }
      ],
      "get": {
        "operationId": "unread",
        "summary": "How many tickets have replies the user hasn't read",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "responses": {
          "200": {
            "description": "The count, for a badge.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "count"
                  ],
                  "properties": {
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/games/{publicKey}/me": {
      "parameters": [
        {
          "name": "publicKey",
          "in": "path",
          "required": true,
          "description": "The product's public key, jk_... (safe in client code).",
          "schema": {
            "type": "string",
            "pattern": "^jk_"
          }
        }
      ],
      "delete": {
        "operationId": "deleteMe",
        "summary": "Delete everything this user has sent",
        "description": "Every ticket, message and file of the user making the request. Can't be undone.",
        "security": [
          {
            "playerToken": []
          },
          {
            "anonymousId": []
          }
        ],
        "responses": {
          "200": {
            "description": "What was deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "deleted"
                  ],
                  "properties": {
                    "deleted": {
                      "type": "object",
                      "required": [
                        "tickets",
                        "files"
                      ],
                      "properties": {
                        "tickets": {
                          "type": "integer"
                        },
                        "files": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No user identity, a bad or expired token, or tokens/anonymous ids not allowed for this product.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Called from a browser page whose origin isn't one of the product's web addresses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown public key, or a ticket that isn't this user's.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait the number of seconds in Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/v1/releases": {
      "post": {
        "operationId": "release",
        "summary": "Say a version is out (from a deploy script)",
        "description": "Every fix waiting for a release (tickets whose GitHub issue was closed as completed) is marked released, and each user who reported it is told. Make the release key on the desk's Releases page; it names the product.",
        "security": [
          {
            "releaseKey": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Release"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "How many tickets were released.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "released",
                    "version"
                  ],
                  "properties": {
                    "released": {
                      "type": "integer"
                    },
                    "version": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The body isn't JSON or a field is wrong.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or unknown release key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "playerToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "A compact JWT your server signs with the product's Ed25519 private key (alg EdDSA). Claims: sub (your user id, up to 200 characters), name (optional), aud (the product's jk_ key), exp (at most 7 days ahead). https://desk.juncodesk.app/docs/user-tokens.md"
      },
      "anonymousId": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Junco-Player",
        "description": "For products that allow users without accounts: 32 to 128 URL-safe random characters ([A-Za-z0-9_-]) made once per install and kept. Losing it loses access to that user's tickets."
      },
      "releaseKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "The product's release key, jr_..., from the Releases page. A secret: keep it in your CI's secrets."
      }
    },
    "schemas": {
      "NewTicket": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "bug",
              "idea",
              "help"
            ]
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 140
          },
          "handle": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
          },
          "context": {
            "default": {},
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          }
        },
        "required": [
          "type",
          "text"
        ]
      },
      "NewReply": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5000
          }
        },
        "required": [
          "text"
        ]
      },
      "Ticket": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number"
          },
          "type": {
            "type": "string",
            "enum": [
              "bug",
              "idea",
              "help"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "needs_you",
              "ai_handling",
              "waiting_on_player",
              "resolved"
            ]
          },
          "stage": {
            "type": "string",
            "enum": [
              "needs_you",
              "ai_handling",
              "waiting_on_player",
              "in_progress",
              "awaiting_release",
              "resolved",
              "released"
            ]
          },
          "title": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "lastMessageAt": {
            "type": "string"
          },
          "unread": {
            "type": "boolean"
          }
        },
        "required": [
          "number",
          "type",
          "status",
          "title",
          "createdAt",
          "lastMessageAt",
          "unread"
        ],
        "additionalProperties": false
      },
      "TicketDetail": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number"
          },
          "type": {
            "type": "string",
            "enum": [
              "bug",
              "idea",
              "help"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "needs_you",
              "ai_handling",
              "waiting_on_player",
              "resolved"
            ]
          },
          "stage": {
            "type": "string",
            "enum": [
              "needs_you",
              "ai_handling",
              "waiting_on_player",
              "in_progress",
              "awaiting_release",
              "resolved",
              "released"
            ]
          },
          "title": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "lastMessageAt": {
            "type": "string"
          },
          "unread": {
            "type": "boolean"
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "from": {
                  "type": "string",
                  "enum": [
                    "player",
                    "ai",
                    "staff"
                  ]
                },
                "text": {
                  "type": "string"
                },
                "at": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "from",
                "text",
                "at"
              ],
              "additionalProperties": false
            }
          },
          "aiWorking": {
            "default": false,
            "type": "boolean"
          }
        },
        "required": [
          "number",
          "type",
          "status",
          "title",
          "createdAt",
          "lastMessageAt",
          "unread",
          "messages",
          "aiWorking"
        ],
        "additionalProperties": false
      },
      "Release": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "maxLength": 40,
            "pattern": "^[\\w.+\\- ]*$"
          },
          "issues": {
            "maxItems": 200,
            "type": "array",
            "items": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    }
  }
}