{
  "openapi": "3.1.0",
  "info": {
    "title": "Ring Round API",
    "version": "1.0.0",
    "summary": "The public, supported part of the Ring Round REST API: phones and their health, the two phone commands, the staff record, phone assignments, team membership and branches.",
    "description": "This document describes a deliberately chosen part of the API that the Ring Round console itself runs on: the operations that are stable enough for an organisation's own IT team, and later Zapier and Power Automate, to build on. Console-only operations are not listed here.\n\nAccess today: on request, not self-serve. Calls authenticate with the bearer sign-in token of one of your organisation's Ring Round administrators, and each token lasts at most 24 hours. There are no long-lived integration keys or third-party sign-in yet. Self-serve access for other applications is planned, and will use OAuth 2.0 only.\n\nScope: every call sees exactly what the administrator whose token it uses could see in the console, either the whole organisation or one branch. A record outside that scope gets the same 404 as one that does not exist.\n\nRecorded: every change made through these operations is written to the organisation's activity record, the same as a change made in the console.\n\nErrors: error responses have a short plain-text body, not JSON.",
    "contact": {
      "name": "Ring Round",
      "url": "/get-in-touch/?reason=integrations"
    }
  },
  "servers": [
    {
      "url": "https://{host}",
      "description": "Your organisation's Ring Round address, given to you with API access.",
      "variables": {
        "host": {
          "default": "your-ring-round-address",
          "description": "Given to you with API access."
        }
      }
    }
  ],
  "security": [
    { "bearerAuth": [] }
  ],
  "tags": [
    { "name": "Phones", "description": "The phones in your organisation, and their health." },
    { "name": "Phone commands", "description": "The two commands Ring Round can send to a phone: LOCK and SYNC. Ring Round sends each command and records it with a delivery status. Once our Android Enterprise integration is live, a real phone carries out lock and resync through Google's Android Management API rather than Ring Round's own channel, which is not live yet." },
    { "name": "Staff", "description": "The staff record. Part of the staff API, which is switched on for each organisation as part of its agreement with us. Without it these operations return 403." },
    { "name": "Phone assignments", "description": "Who holds which phone. Part of the staff API. One person can hold several phones, and a shared phone can be assigned to several people. Assignments are closed rather than deleted, so history is kept." },
    { "name": "Teams", "description": "Teams and their members. A team decides whose contacts appear on whose phones, so keeping membership current keeps every phone's contact list current." },
    { "name": "Branches", "description": "The branches (sites) in your organisation." }
  ],
  "paths": {
    "/api/admin/devices": {
      "get": {
        "tags": ["Phones"],
        "operationId": "listPhones",
        "summary": "List phones",
        "description": "Every phone visible to the caller, in serial-number order, a page at a time.",
        "parameters": [
          { "$ref": "#/components/parameters/Limit" },
          { "$ref": "#/components/parameters/Offset" }
        ],
        "responses": {
          "200": {
            "description": "A page of phones.",
            "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Phone" } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/api/admin/devices/{serial}": {
      "get": {
        "tags": ["Phones"],
        "operationId": "getPhone",
        "summary": "Get a phone",
        "parameters": [{ "$ref": "#/components/parameters/Serial" }],
        "responses": {
          "200": { "description": "The phone.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Phone" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/fleet/device-health": {
      "get": {
        "tags": ["Phones"],
        "operationId": "listPhoneHealth",
        "summary": "Health of every phone",
        "description": "One row per visible phone: whether it is connected now, and its most recent battery report. A phone that has never connected or reported is still listed, with online false and the other fields null.",
        "parameters": [
          { "name": "limit", "in": "query", "required": false, "description": "Phones per page, 1 to 500.", "schema": { "type": "integer", "minimum": 1, "maximum": 500, "default": 100 } },
          { "$ref": "#/components/parameters/Offset" }
        ],
        "responses": {
          "200": { "description": "One health row per phone in the page.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/PhoneHealth" } } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/api/admin/devices/{serial}/presence": {
      "get": {
        "tags": ["Phones"],
        "operationId": "getPhonePresence",
        "summary": "Is a phone connected now",
        "description": "Whether the phone is connected to Ring Round's secure channel right now. A phone that has never connected is reported as offline, not as an error.",
        "parameters": [{ "$ref": "#/components/parameters/Serial" }],
        "responses": {
          "200": { "description": "The phone's connection state.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Presence" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/devices/{serial}/groups": {
      "get": {
        "tags": ["Phones", "Teams"],
        "operationId": "listPhoneTeams",
        "summary": "Teams on a phone's contact list",
        "description": "The teams whose contact lists this phone currently receives.",
        "parameters": [{ "$ref": "#/components/parameters/Serial" }],
        "responses": {
          "200": { "description": "The phone's teams.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/TeamSummary" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/devices/{serial}/commands": {
      "post": {
        "tags": ["Phone commands"],
        "operationId": "sendPhoneCommand",
        "summary": "Send a command",
        "description": "Sends LOCK or SYNC and records it in the phone's command history. A 201 means Ring Round sent the command; whether the phone has received it shows as the command's status in the history. Once our Android Enterprise integration is live, a real phone carries out lock and resync through Google's Android Management API rather than this channel, which is not live yet.",
        "parameters": [{ "$ref": "#/components/parameters/Serial" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CommandRequest" },
              "examples": {
                "lock": { "summary": "Lock, with a message", "value": { "command_type": "LOCK", "payload": { "message": "Please return this phone to the office." } } },
                "sync": { "summary": "Resync everything", "value": { "command_type": "SYNC" } }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Sent and recorded.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CommandSent" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "502": { "$ref": "#/components/responses/SendFailed" }
        }
      },
      "get": {
        "tags": ["Phone commands"],
        "operationId": "listPhoneCommands",
        "summary": "Command history",
        "description": "Commands sent to this phone over either channel, newest first, with their delivery status.",
        "parameters": [
          { "$ref": "#/components/parameters/Serial" },
          { "name": "limit", "in": "query", "required": false, "description": "Most recent commands to return.", "schema": { "type": "integer", "minimum": 1, "default": 100 } }
        ],
        "responses": {
          "200": { "description": "The phone's command history.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/CommandRecord" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/devices/{serial}/sms-commands": {
      "post": {
        "tags": ["Phone commands"],
        "operationId": "sendPhoneCommandBySms",
        "summary": "Send a command by text message",
        "description": "The fallback channel for a phone that is not connected: sends a signed LOCK or SYNC by text message to the phone's own number, and records it in the same command history. The phone must have a number on file.",
        "parameters": [{ "$ref": "#/components/parameters/Serial" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SmsCommandRequest" },
              "examples": {
                "lock": { "summary": "Lock, with a message", "value": { "command_type": "LOCK", "message": "Please return this phone to the office." } }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Sent and recorded.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SmsCommandSent" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "422": { "description": "The phone has no number on file to text.", "content": { "text/plain": { "schema": { "type": "string" } } } },
          "502": { "$ref": "#/components/responses/SendFailed" }
        }
      }
    },
    "/api/admin/staff": {
      "get": {
        "tags": ["Staff"],
        "operationId": "listStaff",
        "summary": "List staff",
        "description": "Everyone in the staff record visible to the caller, excluding people marked as having left.",
        "parameters": [{ "$ref": "#/components/parameters/SiteFilter" }],
        "responses": {
          "200": { "description": "Staff records.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Staff" } } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" }
        }
      },
      "post": {
        "tags": ["Staff"],
        "operationId": "createStaff",
        "summary": "Add a person",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/NewStaff" },
              "example": { "site_id": 12, "name": "Priya Shah", "email": "priya.shah@example.org", "external_ref": "HR-00417", "phone_number": "+44 7700 900123", "job_title": "Care worker" }
            }
          }
        },
        "responses": {
          "201": { "description": "Created.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Staff" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "description": "The branch named in the body is not visible to the caller.", "content": { "text/plain": { "schema": { "type": "string" } } } },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      }
    },
    "/api/admin/staff/{id}": {
      "parameters": [{ "$ref": "#/components/parameters/StaffId" }],
      "get": {
        "tags": ["Staff"],
        "operationId": "getStaff",
        "summary": "Get a person",
        "responses": {
          "200": { "description": "The staff record.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Staff" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      },
      "put": {
        "tags": ["Staff"],
        "operationId": "updateStaff",
        "summary": "Update a person",
        "description": "A partial update: fields left out are unchanged.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UpdateStaff" } } } },
        "responses": {
          "200": { "description": "The updated record.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Staff" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      },
      "delete": {
        "tags": ["Staff"],
        "operationId": "markStaffAsLeft",
        "summary": "Mark a person as having left",
        "description": "Sets deleted_at on the record. Nothing is deleted: the record and its phone-assignment history are kept. The person no longer appears in the staff list or on colleagues' phones. There is no operation to reverse this through the API.",
        "responses": {
          "200": { "description": "The record, now marked as having left.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Staff" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/staff/{id}/groups": {
      "get": {
        "tags": ["Staff", "Teams"],
        "operationId": "listStaffTeams",
        "summary": "Teams a person is in",
        "description": "This person's current team memberships. Part of the staff API.",
        "parameters": [{ "$ref": "#/components/parameters/StaffId" }],
        "responses": {
          "200": { "description": "Current memberships.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Membership" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/staff/{id}/devices": {
      "get": {
        "tags": ["Phone assignments"],
        "operationId": "listStaffPhones",
        "summary": "Phones a person holds",
        "parameters": [
          { "$ref": "#/components/parameters/StaffId" },
          { "$ref": "#/components/parameters/IncludeHistory" }
        ],
        "responses": {
          "200": { "description": "Assignments.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Assignment" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/staff/{id}/devices/{serial}": {
      "parameters": [
        { "$ref": "#/components/parameters/StaffId" },
        { "$ref": "#/components/parameters/Serial" }
      ],
      "post": {
        "tags": ["Phone assignments"],
        "operationId": "assignPhone",
        "summary": "Assign a phone to a person",
        "description": "The phone must belong to the same organisation as the person. Assigning the same phone to the same person twice while the first assignment is open is refused with 409.",
        "responses": {
          "201": { "description": "Assigned.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Assignment" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      },
      "delete": {
        "tags": ["Phone assignments"],
        "operationId": "unassignPhone",
        "summary": "Unassign a phone from a person",
        "description": "Closes the open assignment by setting unassigned_at. The assignment is kept as history, and the phone can be assigned again at any time.",
        "responses": {
          "200": { "description": "The closed assignment.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Assignment" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "description": "No open assignment for this person and phone, or not visible to the caller.", "content": { "text/plain": { "schema": { "type": "string" } } } }
        }
      }
    },
    "/api/admin/devices/{serial}/staff": {
      "get": {
        "tags": ["Phone assignments"],
        "operationId": "listPhoneHolders",
        "summary": "People who hold a phone",
        "parameters": [
          { "$ref": "#/components/parameters/Serial" },
          { "$ref": "#/components/parameters/IncludeHistory" }
        ],
        "responses": {
          "200": { "description": "Assignments.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Assignment" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/StaffApiOff" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/groups": {
      "get": {
        "tags": ["Teams"],
        "operationId": "listTeams",
        "summary": "List teams",
        "parameters": [{ "$ref": "#/components/parameters/SiteFilter" }],
        "responses": {
          "200": { "description": "Teams.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Team" } } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/api/admin/groups/{id}": {
      "get": {
        "tags": ["Teams"],
        "operationId": "getTeam",
        "summary": "Get a team",
        "parameters": [{ "$ref": "#/components/parameters/TeamId" }],
        "responses": {
          "200": { "description": "The team.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Team" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/groups/{id}/members": {
      "get": {
        "tags": ["Teams"],
        "operationId": "listTeamMembers",
        "summary": "List a team's members",
        "description": "Current members only.",
        "parameters": [{ "$ref": "#/components/parameters/TeamId" }],
        "responses": {
          "200": { "description": "Current memberships.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Membership" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/groups/{id}/members/{staff_id}": {
      "parameters": [
        { "$ref": "#/components/parameters/TeamId" },
        { "name": "staff_id", "in": "path", "required": true, "description": "The person's id.", "schema": { "type": "integer", "format": "int64" } }
      ],
      "post": {
        "tags": ["Teams"],
        "operationId": "addTeamMember",
        "summary": "Add a person to a team",
        "responses": {
          "201": { "description": "Added.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Membership" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      },
      "delete": {
        "tags": ["Teams"],
        "operationId": "removeTeamMember",
        "summary": "Remove a person from a team",
        "description": "Ends the current membership by setting ended_at. The membership is kept as history, and the person can be added again at any time.",
        "responses": {
          "200": { "description": "The ended membership.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Membership" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/api/admin/sites": {
      "get": {
        "tags": ["Branches"],
        "operationId": "listBranches",
        "summary": "List branches",
        "description": "The branches visible to the caller: every branch in the organisation, or the caller's own branch.",
        "responses": {
          "200": { "description": "Branches.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Branch" } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/api/admin/sites/{id}": {
      "get": {
        "tags": ["Branches"],
        "operationId": "getBranch",
        "summary": "Get a branch",
        "parameters": [{ "name": "id", "in": "path", "required": true, "description": "The branch's id.", "schema": { "type": "integer", "format": "int64" } }],
        "responses": {
          "200": { "description": "The branch.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Branch" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "The sign-in token of one of your organisation's Ring Round administrators. It lasts at most 24 hours, and stops working at once if that administrator is disabled or signed out everywhere. Access is available on request; there is no self-serve sign-up for other applications yet. When self-serve access arrives it will use OAuth 2.0 only."
      }
    },
    "parameters": {
      "Serial": { "name": "serial", "in": "path", "required": true, "description": "The phone's serial number.", "schema": { "type": "string" } },
      "StaffId": { "name": "id", "in": "path", "required": true, "description": "The person's id.", "schema": { "type": "integer", "format": "int64" } },
      "TeamId": { "name": "id", "in": "path", "required": true, "description": "The team's id.", "schema": { "type": "integer", "format": "int64" } },
      "Limit": { "name": "limit", "in": "query", "required": false, "description": "Items per page.", "schema": { "type": "integer", "minimum": 1, "default": 100 } },
      "Offset": { "name": "offset", "in": "query", "required": false, "description": "Items to skip.", "schema": { "type": "integer", "minimum": 0, "default": 0 } },
      "SiteFilter": { "name": "site_id", "in": "query", "required": false, "description": "Only this branch.", "schema": { "type": "integer", "format": "int64" } },
      "IncludeHistory": { "name": "include_history", "in": "query", "required": false, "description": "true also returns closed assignments. By default only open ones are returned.", "schema": { "type": "boolean", "default": false } }
    },
    "responses": {
      "Unauthorized": { "description": "Missing, malformed, expired or revoked token.", "content": { "text/plain": { "schema": { "type": "string" }, "example": "invalid or expired admin token" } } },
      "BadRequest": { "description": "A malformed body or parameter.", "content": { "text/plain": { "schema": { "type": "string" } } } },
      "NotFound": { "description": "Does not exist, or is outside the caller's scope. The two are deliberately indistinguishable.", "content": { "text/plain": { "schema": { "type": "string" } } } },
      "Conflict": { "description": "Conflicts with an existing record, for example an assignment or membership that is already open.", "content": { "text/plain": { "schema": { "type": "string" }, "example": "conflicts with an existing record" } } },
      "StaffApiOff": { "description": "The staff API is not switched on for this organisation.", "content": { "text/plain": { "schema": { "type": "string" } } } },
      "Forbidden": { "description": "The caller's job title does not grant the permission this operation needs.", "content": { "text/plain": { "schema": { "type": "string" } } } },
      "SendFailed": { "description": "Ring Round could not hand the command to the secure channel or the text-message gateway. The attempt is still recorded in the command history with status failed.", "content": { "text/plain": { "schema": { "type": "string" } } } }
    },
    "schemas": {
      "Phone": {
        "type": "object",
        "required": ["serial", "device_group", "status", "enrollment_verified", "tenant_id", "site_id", "created_at", "updated_at"],
        "properties": {
          "serial": { "type": "string", "description": "The phone's serial number, its identifier everywhere in the API." },
          "device_number": { "type": ["string", "null"], "description": "The phone's own mobile number, used for text-message commands." },
          "device_group": { "type": "string" },
          "model": { "type": ["string", "null"] },
          "android_id": { "type": ["string", "null"] },
          "imei": { "type": ["string", "null"] },
          "status": { "type": "string", "description": "Where the phone is in set-up, for example active." },
          "enrollment_verified": { "type": "boolean", "description": "true once the phone has proved it holds its Ring Round certificate." },
          "enrolled_at": { "type": ["string", "null"], "format": "date-time" },
          "cert_serial": { "type": ["string", "null"] },
          "cert_issued_at": { "type": ["string", "null"], "format": "date-time" },
          "info_json": { "type": ["object", "null"], "description": "Details the phone reported about itself during set-up." },
          "tenant_id": { "type": "integer", "format": "int64", "description": "Your organisation." },
          "site_id": { "type": "integer", "format": "int64", "description": "The phone's branch." },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "PhoneHealth": {
        "type": "object",
        "required": ["serial", "online"],
        "properties": {
          "serial": { "type": "string" },
          "online": { "type": "boolean", "description": "Connected to Ring Round's secure channel right now." },
          "presence_last_event_at": { "type": ["string", "null"], "format": "date-time", "description": "When the phone last connected or disconnected, by Ring Round's clock." },
          "last_telemetry_at": { "type": ["string", "null"], "format": "date-time", "description": "Time of the most recent health report received, by the phone's clock." },
          "battery_pct": { "type": ["integer", "null"], "minimum": 0, "maximum": 100 },
          "is_charging": { "type": ["boolean", "null"] }
        }
      },
      "Presence": {
        "type": "object",
        "required": ["serial", "online"],
        "properties": {
          "serial": { "type": "string" },
          "online": { "type": "boolean" },
          "last_event_at": { "type": "string", "format": "date-time", "description": "When the phone last connected or disconnected. Left out if it never has." }
        }
      },
      "CommandRequest": {
        "type": "object",
        "required": ["command_type"],
        "properties": {
          "command_type": { "type": "string", "enum": ["LOCK", "SYNC"], "description": "LOCK: show the lock screen, with an optional message. SYNC: fetch the whole set-up again (apps, home screen, contacts and settings). These are the only two commands Ring Round defines." },
          "payload": {
            "type": "object",
            "description": "Optional details carried to the phone with the command.",
            "properties": {
              "message": { "type": "string", "description": "LOCK only: a message for the lock screen, such as where to return the phone." }
            }
          }
        }
      },
      "CommandSent": {
        "type": "object",
        "required": ["command_log_id", "status"],
        "properties": {
          "command_log_id": { "type": "integer", "format": "int64", "description": "The command's id in the command history." },
          "status": { "type": "string", "const": "sent" }
        }
      },
      "SmsCommandRequest": {
        "type": "object",
        "required": ["command_type"],
        "properties": {
          "command_type": { "type": "string", "enum": ["LOCK", "SYNC"] },
          "message": { "type": "string", "description": "LOCK only. Sending a message with SYNC is refused with 400." }
        }
      },
      "SmsCommandSent": {
        "type": "object",
        "required": ["command_log_id", "channel", "status"],
        "properties": {
          "command_log_id": { "type": "integer", "format": "int64" },
          "channel": { "type": "string", "const": "sms" },
          "status": { "type": "string", "const": "sent" }
        }
      },
      "CommandRecord": {
        "type": "object",
        "required": ["id", "serial", "command_type", "channel", "status", "issued_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "serial": { "type": "string" },
          "command_type": { "type": "string", "description": "LOCK or SYNC for commands sent through this API. The history can also hold Ring Round's own automatic messages, such as a mobile-data allowance warning." },
          "channel": { "type": "string", "enum": ["secure_channel", "sms"], "description": "secure_channel: Ring Round's own secure channel. sms: text message." },
          "payload": { "type": ["object", "null"] },
          "status": { "type": "string", "enum": ["pending", "sent", "acked", "failed"], "description": "acked means the phone has confirmed receipt." },
          "issued_at": { "type": "string", "format": "date-time" },
          "acked_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "Staff": {
        "type": "object",
        "required": ["id", "tenant_id", "site_id", "name", "email", "created_at", "updated_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "tenant_id": { "type": "integer", "format": "int64" },
          "site_id": { "type": "integer", "format": "int64", "description": "The person's home branch." },
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "external_ref": { "type": ["string", "null"], "description": "Your own system's identifier for this person. Ring Round stores it and never interprets it." },
          "phone_number": { "type": ["string", "null"], "description": "The number colleagues' phones show for this person. A person without one is left out of contact lists." },
          "job_title": { "type": ["string", "null"] },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "deleted_at": { "type": "string", "format": "date-time", "description": "When the person was marked as having left. Only present on such a record." }
        }
      },
      "NewStaff": {
        "type": "object",
        "required": ["site_id", "name", "email"],
        "properties": {
          "site_id": { "type": "integer", "format": "int64" },
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "external_ref": { "type": ["string", "null"] },
          "phone_number": { "type": ["string", "null"], "pattern": "^\\+?[0-9 ()-]{7,20}$" },
          "job_title": { "type": ["string", "null"] }
        }
      },
      "UpdateStaff": {
        "type": "object",
        "description": "Every field is optional. A field left out is unchanged.",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "external_ref": { "type": "string" },
          "phone_number": { "type": "string", "pattern": "^$|^\\+?[0-9 ()-]{7,20}$" },
          "job_title": { "type": "string" },
          "site_id": { "type": "integer", "format": "int64", "description": "Move the person to another branch the caller can see." }
        }
      },
      "Assignment": {
        "type": "object",
        "required": ["id", "staff_id", "serial", "tenant_id", "site_id", "assigned_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "staff_id": { "type": "integer", "format": "int64" },
          "serial": { "type": "string" },
          "tenant_id": { "type": "integer", "format": "int64" },
          "site_id": { "type": "integer", "format": "int64" },
          "assigned_at": { "type": "string", "format": "date-time" },
          "assigned_by_admin_user_id": { "type": ["integer", "null"], "format": "int64" },
          "unassigned_at": { "type": "string", "format": "date-time", "description": "Present once the assignment is closed." },
          "unassigned_by_admin_user_id": { "type": "integer", "format": "int64" }
        }
      },
      "Team": {
        "type": "object",
        "required": ["id", "tenant_id", "name", "contact_version", "created_at", "updated_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "tenant_id": { "type": "integer", "format": "int64" },
          "site_id": { "type": "integer", "format": "int64", "description": "Left out for an organisation-wide team." },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "contact_version": { "type": "integer", "format": "int64", "description": "Goes up whenever the team's contact list changes." },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "TeamSummary": {
        "type": "object",
        "required": ["id", "name", "contact_version"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "site_id": { "type": "integer", "format": "int64" },
          "name": { "type": "string" },
          "contact_version": { "type": "integer", "format": "int64" }
        }
      },
      "Membership": {
        "type": "object",
        "required": ["id", "staff_id", "group_id", "tenant_id", "site_id", "joined_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "staff_id": { "type": "integer", "format": "int64" },
          "group_id": { "type": "integer", "format": "int64", "description": "The team's id." },
          "tenant_id": { "type": "integer", "format": "int64" },
          "site_id": { "type": "integer", "format": "int64" },
          "joined_at": { "type": "string", "format": "date-time" },
          "added_by_admin_user_id": { "type": "integer", "format": "int64" },
          "ended_at": { "type": "string", "format": "date-time", "description": "Present once the membership has ended." },
          "ended_by_admin_user_id": { "type": "integer", "format": "int64" }
        }
      },
      "Branch": {
        "type": "object",
        "required": ["id", "tenant_id", "name", "created_at"],
        "properties": {
          "id": { "type": "integer", "format": "int64" },
          "tenant_id": { "type": "integer", "format": "int64" },
          "name": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
