{
 "openapi": "3.0.3",
 "info": {
  "title": "Mirialabs API",
  "version": "2.0.0",
  "description": "REST API of the Mirialabs Manager for organisations (Premium+). Keys are made in the Manager, Organisation › API keys, and sent as `Authorization: Bearer mlk_…`. JSON in and out, times in UTC (ISO 8601). Errors: `{\"error\": {\"code\", \"message\"}}`. 600 requests per minute per key (headers X-RateLimit-*). Guide: https://mirialabs.com/developers"
 },
 "servers": [
  {
   "url": "https://mirialabs.com/api/v2"
  }
 ],
 "security": [
  {
   "apiKey": []
  }
 ],
 "tags": [
  {
   "name": "Key"
  },
  {
   "name": "Sites"
  },
  {
   "name": "People"
  },
  {
   "name": "Groups"
  },
  {
   "name": "Doors"
  },
  {
   "name": "Activity"
  },
  {
   "name": "Reports"
  }
 ],
 "paths": {
  "/me": {
   "get": {
    "summary": "The key",
    "description": "The key's name, scopes, sites and organisation.",
    "tags": [
     "Key"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites": {
   "get": {
    "summary": "List sites",
    "description": "The sites the key can reach. `synced`: people, groups and doors are only available on synced sites.",
    "tags": [
     "Sites"
    ],
    "parameters": [],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Site"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/groups": {
   "get": {
    "summary": "List groups",
    "description": "Groups of the site. A person's groups decide which doors they may open, and when.\n\nScope: `people:read`.",
    "tags": [
     "Groups"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Group"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a group",
    "description": "Adds a group to the site. Without a color, one is chosen. 409 `conflict` when the site already has a group with this name. Then give it access in the Manager (Access policies), and put people in it with the people endpoints (`groups`).\n\nScope: `people:write`.",
    "tags": [
     "Groups"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     }
    ],
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Group"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "422": {
      "description": "Invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "invalid",
          "message": "first_name and last_name are required."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/GroupInput"
       }
      }
     }
    }
   }
  },
  "/sites/{site}/groups/{group}": {
   "get": {
    "summary": "Get a group",
    "description": "\n\nScope: `people:read`.",
    "tags": [
     "Groups"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "group",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Group id (GET /sites/{site}/groups)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Group"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   },
   "patch": {
    "summary": "Change a group",
    "description": "Only the fields sent change. A renamed group keeps its people and its access. Groups managed for the whole organisation answer 409 `managed_by_organisation`.\n\nScope: `people:write`.",
    "tags": [
     "Groups"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "group",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Group id (GET /sites/{site}/groups)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Group"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "422": {
      "description": "Invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "invalid",
          "message": "first_name and last_name are required."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/GroupPatch"
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Delete a group",
    "description": "Removes the group from the site and its devices. Its people stay, without this group and the access it gave them.\n\nScope: `people:write`.",
    "tags": [
     "Groups"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "group",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Group id (GET /sites/{site}/groups)."
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/people": {
   "get": {
    "summary": "List people",
    "description": "People of the site, paged.\n\nScope: `people:read`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Search in name, card number, email."
     },
     {
      "name": "group",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only this group (name)."
     },
     {
      "name": "page",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      },
      "description": "Page, from 1."
     },
     {
      "name": "per_page",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 50
      },
      "description": "Items per page."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Person"
           }
          },
          "pagination": {
           "$ref": "#/components/schemas/Pagination"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Add a person",
    "description": "Adds a person to the site. The devices get them within seconds. 409 `conflict` if the card is already used on the site: change that person with PATCH /people/card/{card_number}. 403 `plan_limit` when the plan's people limit is reached.\n\nScope: `people:write`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     }
    ],
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "422": {
      "description": "Invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "invalid",
          "message": "first_name and last_name are required."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PersonInput"
       }
      }
     }
    }
   }
  },
  "/sites/{site}/people/{person}": {
   "get": {
    "summary": "Get a person",
    "description": "\n\nScope: `people:read`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "person",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Person id."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "operationId": "getPersonById"
   },
   "patch": {
    "summary": "Change a person",
    "description": "Only the fields sent change. Turn a person off with `{\"active\": false}` (they keep their card and groups), or give their full list of `groups`. The card number cannot change. People managed for the whole organisation answer 409 `managed_by_organisation`.\n\nScope: `people:write`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "person",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Person id."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "422": {
      "description": "Invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "invalid",
          "message": "first_name and last_name are required."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PersonPatch"
       }
      }
     }
    },
    "operationId": "changePersonById"
   },
   "delete": {
    "summary": "Delete a person",
    "description": "Removes the person from the site and its devices: their card stops working. To stop access for a while, PATCH `{\"active\": false}` instead.\n\nScope: `people:write`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "person",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Person id."
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "operationId": "deletePersonById"
   }
  },
  "/sites/{site}/people/card/{card_number}": {
   "get": {
    "summary": "Get a person (by card number)",
    "description": "\n\nScope: `people:read`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "card_number",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The person's card number."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "operationId": "getPersonByCard"
   },
   "patch": {
    "summary": "Change a person (by card number)",
    "description": "Only the fields sent change. Turn a person off with `{\"active\": false}` (they keep their card and groups), or give their full list of `groups`. The card number cannot change. People managed for the whole organisation answer 409 `managed_by_organisation`.\n\nScope: `people:write`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "card_number",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The person's card number."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "422": {
      "description": "Invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "invalid",
          "message": "first_name and last_name are required."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PersonPatch"
       }
      }
     }
    },
    "operationId": "changePersonByCard"
   },
   "delete": {
    "summary": "Delete a person (by card number)",
    "description": "Removes the person from the site and its devices: their card stops working. To stop access for a while, PATCH `{\"active\": false}` instead.\n\nScope: `people:write`.",
    "tags": [
     "People"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "card_number",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "The person's card number."
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    },
    "operationId": "deletePersonByCard"
   }
  },
  "/sites/{site}/doors": {
   "get": {
    "summary": "List doors",
    "description": "Doors of the site.",
    "tags": [
     "Doors"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Door"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/doors/{door}/open": {
   "post": {
    "summary": "Open a door",
    "description": "Opens the door for its usual time. 202: the order was sent; the opening shows in the events with type `remote`. 409 `device_offline` when its controller is offline.\n\nScope: `doors:open`.",
    "tags": [
     "Doors"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "door",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Door id (GET /sites/{site}/doors)."
     }
    ],
    "responses": {
     "202": {
      "description": "Accepted",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "object",
           "properties": {
            "door": {
             "type": "string"
            },
            "request_id": {
             "type": "string"
            },
            "status": {
             "type": "string",
             "example": "sent"
            }
           }
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "Conflict",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "site_not_synced",
          "message": "This site still uses the old device-by-device mode. Ask us to switch it to cloud sync to use this endpoint."
         }
        }
       }
      }
     },
     "502": {
      "description": "Not done by the device",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_opened",
          "message": "The device did not open the door. Try again."
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/events": {
   "get": {
    "summary": "List access events",
    "description": "Badge, button, remote, Geo and schedule events, newest first.\n\nScope: `events:read`.",
    "tags": [
     "Activity"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Start: ISO 8601 date (a day of the site's time zone) or date-time. Default: 7 days before `to`."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "End: ISO 8601 date (included) or date-time. Default: now. 92 days at most from `from`."
     },
     {
      "name": "card_number",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only this person."
     },
     {
      "name": "door",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only this door id."
     },
     {
      "name": "result",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "granted",
        "denied"
       ]
      },
      "description": "granted or denied."
     },
     {
      "name": "page",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      },
      "description": "Page, from 1."
     },
     {
      "name": "per_page",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 200,
       "default": 50
      },
      "description": "Items per page."
     },
     {
      "name": "format",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv",
        "xlsx"
       ],
       "default": "json"
      },
      "description": "json (default), csv or xlsx (Excel)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Event"
           }
          },
          "pagination": {
           "$ref": "#/components/schemas/Pagination"
          }
         }
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       },
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/presence": {
   "get": {
    "summary": "Who is on site now",
    "description": "People in a zone now: last seen entering it in the last 24 hours, no exit since.\n\nScope: `events:read`.",
    "tags": [
     "Activity"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "count": {
           "type": "integer"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Presence"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/reports/timesheets": {
   "get": {
    "summary": "Timesheets",
    "description": "One row per person and day (the site's time zone): first and last time seen (badge readers and Geo), the time between them, the time in zones, and the number of events.\n\nScope: `reports:read`.",
    "tags": [
     "Reports"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Start: ISO 8601 date (a day of the site's time zone) or date-time. Default: 7 days before `to`."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "End: ISO 8601 date (included) or date-time. Default: now. 92 days at most from `from`."
     },
     {
      "name": "card_number",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Only this person."
     },
     {
      "name": "format",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv",
        "xlsx"
       ],
       "default": "json"
      },
      "description": "json (default), csv or xlsx (Excel)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "timezone": {
           "type": "string"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/TimesheetDay"
           }
          }
         }
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       },
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  },
  "/sites/{site}/reports/most-active": {
   "get": {
    "summary": "Most active people",
    "description": "People with the most granted events over the period.\n\nScope: `reports:read`.",
    "tags": [
     "Reports"
    ],
    "parameters": [
     {
      "name": "site",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Site id (GET /sites)."
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Start: ISO 8601 date (a day of the site's time zone) or date-time. Default: 7 days before `to`."
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "End: ISO 8601 date (included) or date-time. Default: now. 92 days at most from `from`."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "default": 10
      },
      "description": "How many (1 to 100)."
     },
     {
      "name": "format",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv",
        "xlsx"
       ],
       "default": "json"
      },
      "description": "json (default), csv or xlsx (Excel)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ActivePerson"
           }
          }
         }
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       },
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "description": "Unauthorized",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "unauthorized",
          "message": "Missing, unknown, revoked or expired API key. Send it as: Authorization: Bearer mlk_…"
         }
        }
       }
      }
     },
     "403": {
      "description": "Forbidden",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "missing_scope",
          "message": "This key does not have the people:write scope."
         }
        }
       }
      }
     },
     "404": {
      "description": "Not found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "not_found",
          "message": "No site with this id for this key. GET /sites lists them."
         }
        }
       }
      }
     },
     "429": {
      "description": "Too many requests",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "rate_limited",
          "message": "Too many requests: 600 per minute per key."
         }
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "apiKey": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "mlk_ key",
    "description": "An API key from the Manager: Authorization: Bearer mlk_…"
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "enum": [
         "unauthorized",
         "plan_required",
         "missing_scope",
         "not_found",
         "site_not_synced",
         "invalid",
         "conflict",
         "plan_limit",
         "managed_by_organisation",
         "rate_limited",
         "device_offline",
         "not_opened",
         "not_saved"
        ]
       },
       "message": {
        "type": "string"
       }
      }
     }
    }
   },
   "Pagination": {
    "type": "object",
    "properties": {
     "page": {
      "type": "integer"
     },
     "per_page": {
      "type": "integer"
     },
     "total": {
      "type": "integer"
     },
     "total_pages": {
      "type": "integer"
     }
    }
   },
   "Site": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "name": {
      "type": "string"
     },
     "timezone": {
      "type": "string",
      "example": "Africa/Bamako"
     },
     "city": {
      "type": "string"
     },
     "synced": {
      "type": "boolean"
     }
    }
   },
   "Group": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string",
      "example": "Staff"
     },
     "color": {
      "type": "string",
      "nullable": true,
      "example": "#1554B5"
     },
     "description": {
      "type": "string",
      "nullable": true
     },
     "managed_by_organisation": {
      "type": "boolean"
     }
    }
   },
   "GroupInput": {
    "type": "object",
    "required": [
     "name"
    ],
    "properties": {
     "name": {
      "type": "string",
      "example": "Contractors"
     },
     "color": {
      "type": "string",
      "example": "#F7941D",
      "description": "#RRGGBB. Optional: one is chosen if not sent."
     },
     "description": {
      "type": "string",
      "example": "Outside companies"
     }
    }
   },
   "GroupPatch": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "example": "Contractors 2027"
     },
     "color": {
      "type": "string",
      "example": "#17A05D"
     },
     "description": {
      "type": "string"
     }
    }
   },
   "Door": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "device_serial": {
      "type": "string"
     },
     "open_seconds": {
      "type": "integer"
     }
    }
   },
   "Person": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "card_number": {
      "type": "string"
     },
     "ble_tag_address": {
      "type": "string",
      "nullable": true
     },
     "first_name": {
      "type": "string"
     },
     "last_name": {
      "type": "string"
     },
     "email": {
      "type": "string",
      "nullable": true
     },
     "company": {
      "type": "string",
      "nullable": true
     },
     "groups": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "active": {
      "type": "boolean"
     },
     "start_date": {
      "type": "string",
      "nullable": true
     },
     "end_date": {
      "type": "string",
      "nullable": true
     },
     "managed_by_organisation": {
      "type": "boolean"
     },
     "last_seen": {
      "type": "object",
      "nullable": true,
      "properties": {
       "at": {
        "type": "string"
       },
       "reader": {
        "type": "string"
       }
      }
     },
     "sync": {
      "type": "string",
      "description": "applied when every device of the site has the latest version"
     },
     "created_at": {
      "type": "string"
     },
     "updated_at": {
      "type": "string"
     }
    }
   },
   "PersonInput": {
    "type": "object",
    "required": [
     "first_name",
     "last_name"
    ],
    "properties": {
     "first_name": {
      "type": "string"
     },
     "last_name": {
      "type": "string"
     },
     "card_number": {
      "type": "string",
      "description": "Digits (2 to 20). card_number or ble_tag_address is required."
     },
     "ble_tag_address": {
      "type": "string",
      "example": "AA:BB:CC:DD:EE:FF"
     },
     "email": {
      "type": "string"
     },
     "company": {
      "type": "string",
      "description": "Company name (created if new)."
     },
     "groups": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Group names of the site."
     },
     "active": {
      "type": "boolean",
      "default": true
     },
     "start_date": {
      "type": "string",
      "example": "2026-12-01"
     },
     "end_date": {
      "type": "string",
      "example": "2027-06-30"
     }
    }
   },
   "PersonPatch": {
    "type": "object",
    "properties": {
     "first_name": {
      "type": "string"
     },
     "last_name": {
      "type": "string"
     },
     "email": {
      "type": "string"
     },
     "company": {
      "type": "string"
     },
     "groups": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Replaces the groups."
     },
     "active": {
      "type": "boolean"
     },
     "start_date": {
      "type": "string"
     },
     "end_date": {
      "type": "string"
     }
    }
   },
   "Event": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "time": {
      "type": "string",
      "format": "date-time"
     },
     "type": {
      "type": "string",
      "enum": [
       "card",
       "button",
       "remote",
       "geo",
       "linked",
       "schedule",
       "enroll",
       "other"
      ]
     },
     "result": {
      "type": "string",
      "enum": [
       "granted",
       "denied"
      ]
     },
     "direction": {
      "type": "string",
      "enum": [
       "in",
       "out"
      ]
     },
     "person": {
      "type": "object",
      "nullable": true,
      "properties": {
       "card_number": {
        "type": "string"
       },
       "first_name": {
        "type": "string",
        "example": "Moussa"
       },
       "last_name": {
        "type": "string",
        "example": "Diallo"
       },
       "company": {
        "type": "string",
        "nullable": true
       },
       "groups": {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      }
     },
     "door": {
      "type": "object",
      "nullable": true,
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "reader": {
      "type": "object",
      "nullable": true,
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "zone": {
      "type": "string",
      "nullable": true
     },
     "device_serial": {
      "type": "string"
     },
     "detail": {
      "type": "string"
     }
    }
   },
   "Presence": {
    "type": "object",
    "properties": {
     "card_number": {
      "type": "string"
     },
     "first_name": {
      "type": "string",
      "example": "Moussa"
     },
     "last_name": {
      "type": "string",
      "example": "Diallo"
     },
     "company": {
      "type": "string",
      "nullable": true
     },
     "zone": {
      "type": "string"
     },
     "since": {
      "type": "string",
      "format": "date-time"
     },
     "source": {
      "type": "string",
      "enum": [
       "reader",
       "geo"
      ]
     }
    }
   },
   "TimesheetDay": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "format": "date"
     },
     "card_number": {
      "type": "string"
     },
     "first_name": {
      "type": "string",
      "example": "Moussa"
     },
     "last_name": {
      "type": "string",
      "example": "Diallo"
     },
     "company": {
      "type": "string",
      "nullable": true
     },
     "first_seen": {
      "type": "string",
      "format": "date-time"
     },
     "last_seen": {
      "type": "string",
      "format": "date-time"
     },
     "seconds_on_site": {
      "type": "integer"
     },
     "seconds_in_zones": {
      "type": "integer"
     },
     "events": {
      "type": "integer"
     }
    }
   },
   "ActivePerson": {
    "type": "object",
    "properties": {
     "rank": {
      "type": "integer"
     },
     "card_number": {
      "type": "string"
     },
     "first_name": {
      "type": "string",
      "example": "Moussa"
     },
     "last_name": {
      "type": "string",
      "example": "Diallo"
     },
     "company": {
      "type": "string",
      "nullable": true
     },
     "events": {
      "type": "integer"
     },
     "days_present": {
      "type": "integer"
     },
     "last_seen": {
      "type": "string",
      "format": "date-time"
     }
    }
   }
  }
 }
}