{
  "openapi": "3.1.2",
  "info": {
    "title": "packeroo API",
    "version": "1",
    "description": "The public part of the packeroo API. Today it pairs a table device, such as a scoring table, with a table of a location; more operations follow. Guides, examples and the sandbox: https://developers.packeroo.com",
    "contact": {
      "name": "packeroo for developers",
      "email": "info@packeroo.com",
      "url": "https://developers.packeroo.com"
    }
  },
  "servers": [
    {
      "url": "https://api.qm.packeroo.com/api/v1",
      "description": "Sandbox (test keys, pkd_test_…)"
    },
    {
      "url": "https://api.packeroo.com/api/v1",
      "description": "Live"
    }
  ],
  "tags": [
    {
      "name": "Sandbox"
    },
    {
      "name": "Table devices"
    }
  ],
  "paths": {
    "/sandbox/device-pairings/confirm": {
      "servers": [
        {
          "url": "https://api.qm.packeroo.com/api/v1",
          "description": "Sandbox (test keys, pkd_test_…)"
        }
      ],
      "post": {
        "operationId": "device.pairInSandbox",
        "description": "Only in the sandbox (https://api.qm.packeroo.com/api/v1): instead of somebody entering the\ncode in the app, the device claims it itself. It sends the token it got from\n`POST /device-pairings` as `Authorization: Bearer …` and is paired at once with a table of its\nown at the sandbox location; the answer is the device as `GET /device` gives it, which answers\nfrom now on. Live, and everywhere but the sandbox, the answer is 404 `not_found`, but only for\nan otherwise valid request: the `User-Agent` (400 `user_agent_required`) and the\n`Idempotency-Key` (400 `idempotency_key_required`) are checked first.\n\nA device paired in the sandbox already gets itself back, at the same table. A token with no\ncode waiting, because it ran out or was never asked for, gets 401 `unauthenticated`: ask for a\ncode again. So does the token of a device paired at a table outside the sandbox, which this\noperation never moves or shows: it asks `GET /device`. 409 `table_devices_off` while table\ndevices are off. While the sandbox itself is not ready (it is being set up again),\nthe answer is 503 `unavailable`: try again later.\n\nThe sandbox keeps the latest 100 tables; when a new one comes, the oldest that no league plays\nat is archived and its device unpaired. It takes 10 requests an hour and makes 20 new tables a\nday per IP address (an IPv6 address by its /48); above that the answer is 429 `rate_limited`\nwith `Retry-After`.",
        "summary": "Pair this device in the sandbox",
        "tags": [
          "Sandbox"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "A ULID or UUID the client creates for this action. Repeating the request with the same key returns the first answer again, with `Idempotent-Replayed: true`, and has no second effect.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "User-Agent",
            "in": "header",
            "required": true,
            "description": "The product and firmware of the device, such as `Kickertisch/1.2`, so a misbehaving one can be told apart. Without it the answer is 400 `user_agent_required`.",
            "schema": {
              "type": "string"
            },
            "example": "Kickertisch/1.2"
          }
        ],
        "responses": {
          "200": {
            "description": "`DeviceResource`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DeviceResource"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Malformed request, or the idempotency key is missing (`idempotency_key_required`), or the device sends no `User-Agent` (`user_agent_required`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated, or no code waits for the token and no device of the sandbox is paired with it: its code ran out or was never asked for, or the device belongs to a table outside the sandbox (`unauthenticated`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not the sandbox: this operation answers only at https://api.qm.packeroo.com/api/v1 (`not_found`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Conflict with the current state, or a request with the same idempotency key is still running (`request_in_progress`), or table devices are switched off, for the platform or by the owner of the sandbox (`table_devices_off`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed (`validation_failed`), or the idempotency key was used for another request (`idempotency_key_reused`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests (`rate_limited`), with `Retry-After`",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "The sandbox is being set up again; try again later (`unavailable`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {
            "deviceToken": []
          }
        ],
        "x-public": true,
        "x-sandbox-only": true
      }
    },
    "/device-pairings": {
      "post": {
        "operationId": "device.pair",
        "description": "For a device such as a scoring table: a code of six characters to show, valid for\nten minutes, and its token, given only this once. Whoever looks after the location enters the\ncode at a table in the packeroo app; from then on the token signs the\ndevice in as `Authorization: Bearer …`, and `GET /device` answers. A device that asks again\nwith its earlier token gives up its earlier code; one whose code was claimed meanwhile gets\n409 `device_already_paired` and keeps its token, or 409 `table_devices_off` while its\norganization has table devices switched off, and waits. Every request of a device names it in its\n`User-Agent`, such as `Kickertisch/1.2`, or gets 400 `user_agent_required`.",
        "summary": "Ask to pair this device",
        "tags": [
          "Table devices"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "A ULID or UUID the client creates for this action. Repeating the request with the same key returns the first answer again, with `Idempotent-Replayed: true`, and has no second effect.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "User-Agent",
            "in": "header",
            "required": true,
            "description": "The product and firmware of the device, such as `Kickertisch/1.2`, so a misbehaving one can be told apart. Without it the answer is 400 `user_agent_required`.",
            "schema": {
              "type": "string"
            },
            "example": "Kickertisch/1.2"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartDevicePairingRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`DevicePairingResource`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DevicePairingResource"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Malformed request, or the idempotency key is missing (`idempotency_key_required`), or the device sends no `User-Agent` (`user_agent_required`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Conflict with the current state, or a request with the same idempotency key is still running (`request_in_progress`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed (`validation_failed`), or the idempotency key was used for another request (`idempotency_key_reused`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests (`rate_limited`), with `Retry-After`",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {},
          {
            "deviceToken": []
          }
        ],
        "x-public": true
      }
    },
    "/device": {
      "get": {
        "operationId": "device.show",
        "description": "The paired device that asks: its table, location and organization, and what its token may\ndo. A device that is not paired, or no longer, gets 401 and asks to be paired again; so does\nevery device while table devices are switched off for its organization.",
        "summary": "This device",
        "tags": [
          "Table devices"
        ],
        "parameters": [
          {
            "name": "User-Agent",
            "in": "header",
            "required": true,
            "description": "The product and firmware of the device, such as `Kickertisch/1.2`, so a misbehaving one can be told apart. Without it the answer is 400 `user_agent_required`.",
            "schema": {
              "type": "string"
            },
            "example": "Kickertisch/1.2"
          }
        ],
        "responses": {
          "200": {
            "description": "`DeviceResource`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/DeviceResource"
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "The device sends no `User-Agent` (`user_agent_required`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "The token is unknown or revoked, the device is not paired yet, or its organization has table devices switched off (`unauthenticated`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests (`rate_limited`), with `Retry-After`",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {
            "deviceToken": []
          }
        ],
        "x-public": true
      }
    }
  },
  "components": {
    "securitySchemes": {
      "deviceToken": {
        "type": "http",
        "description": "The token a device got when it asked for a pairing code, sent as `Authorization: Bearer pkd_live_…` (`pkd_test_…` in the sandbox). It is shown once and stays valid until the device is unpaired.",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "DevicePairingResource": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "Six capital letters and digits; the device shows them as two groups of three, and as a QR code."
          },
          "expires_at": {
            "type": "string"
          },
          "token": {
            "type": "string",
            "description": "The token the device sends as `Authorization: Bearer …` from now on. It is shown only\nthis once; keep it in a file only the device's user reads. It signs in once the code is\nclaimed: until then `GET /device` answers 401.",
            "examples": [
              "pkd_test_7Hq2xV9pLm3RtY6wQz8NbC4kDf1Gs5Je0aB3cD"
            ]
          }
        },
        "required": [
          "code",
          "expires_at",
          "token"
        ],
        "title": "DevicePairingResource"
      },
      "DeviceResource": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "description": "What it is called at its table, such as \"Kickertisch Halle\"."
          },
          "table": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name"
            ]
          },
          "location": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "time_zone": {
                "type": "string",
                "description": "For the times it shows."
              }
            },
            "required": [
              "id",
              "name",
              "time_zone"
            ]
          },
          "organization": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "name"
            ]
          },
          "scopes": {
            "type": "array",
            "description": "What its token may do, the fixed set of a device.",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "id",
          "name",
          "table",
          "location",
          "organization",
          "scopes"
        ],
        "title": "DeviceResource"
      },
      "Problem": {
        "type": "object",
        "description": "An error, following RFC 9457.",
        "properties": {
          "type": {
            "type": "string",
            "description": "A URL that names the kind of error."
          },
          "title": {
            "type": "string",
            "description": "Short English summary, the same for every occurrence of a code."
          },
          "status": {
            "type": "integer",
            "description": "The HTTP status."
          },
          "detail": {
            "type": "string",
            "description": "What happened and what to do, in the language of the request."
          },
          "code": {
            "type": "string",
            "description": "Stable code of the error; clients branch on it."
          },
          "correlation_id": {
            "type": "string",
            "description": "The ID of the request, also in the header `X-Correlation-Id`."
          },
          "errors": {
            "type": "object",
            "description": "For `validation_failed`: the messages by field.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "detail",
          "code",
          "correlation_id"
        ],
        "title": "Problem"
      },
      "StartDevicePairingRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": [
              "string",
              "null"
            ],
            "description": "What the device says of itself, shown in the list of its table; all optional. Sent\nwithout signing in, so held to what every shown text may hold.",
            "maxLength": 80
          },
          "serial": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 80
          },
          "firmware": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 40
          }
        },
        "title": "StartDevicePairingRequest"
      }
    }
  }
}
