{
 "openapi": "3.1.0",
 "info": {
  "title": "saMas School Apps API (Draft)",
  "version": "1.0.0-draft",
  "description": "**Draft, 29 October 2026. Not switched on yet** (phase 2). The API a school app uses to see one school, only as much as the school and each family agreed to. Read the guide \"Build a school app (Draft)\" first. Answers carry refs that are different for every app, first names and labels; never fees, balances, phone numbers, email addresses or guardians. Calls are server to server with the install's key (X-Api-Key, sk_app_) and, for a person, a user token (Bearer) from POST /apps/token. Operations marked (coming) are described so the first app can be designed; their shapes may still change.",
  "contact": {
   "name": "saMas School apps (address to be created)",
   "email": "apps@samas.school"
  }
 },
 "servers": [
  {
   "url": "https://api.samas.school/v1",
   "description": "Production (not yet open to apps)"
  }
 ],
 "security": [
  {
   "appKey": [],
   "userToken": []
  }
 ],
 "tags": [
  {
   "name": "Install"
  },
  {
   "name": "Tokens"
  },
  {
   "name": "People and classes"
  },
  {
   "name": "Writes"
  },
  {
   "name": "Live and recordings",
   "description": "First-party apps only (built by saMas). Each child's guardian must allow the app."
  }
 ],
 "paths": {
  "/apps/install/exchange": {
   "post": {
    "tags": [
     "Install"
    ],
    "operationId": "appsInstallExchange",
    "summary": "Swap a one-time install code for the install's key and webhook secret",
    "description": "Call from your server when app.installed arrives. Authenticate with your app id and the registration secret you were given when you registered the app (never the install key, which you do not have yet). The code works once, for 10 minutes. The answer is the only time the key and the webhook secret are shown.",
    "security": [
     {
      "appId": [],
      "appSecret": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "install_code"
        ],
        "properties": {
         "install_code": {
          "type": "string",
          "minLength": 20,
          "maxLength": 200
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/InstallCredentials"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "409": {
      "$ref": "#/components/responses/InstallCodeInvalid"
     }
    }
   }
  },
  "/apps/token": {
   "post": {
    "tags": [
     "Tokens"
    ],
    "operationId": "appsToken",
    "summary": "Swap a launch token for a user token",
    "description": "The launch token arrives in your page through the bridge's launch message. Send it from your server with this install's key. It works once, for five minutes, and only with the key of the install it was made for. The user token sees what both the person and your install may see; it lasts 15 minutes; when it runs out, ask your page to send relaunch.",
    "security": [
     {
      "appKey": []
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "launch_token"
        ],
        "properties": {
         "launch_token": {
          "type": "string",
          "minLength": 20,
          "maxLength": 4096
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/UserToken"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "409": {
      "$ref": "#/components/responses/LaunchInvalid"
     }
    }
   }
  },
  "/apps/install": {
   "get": {
    "tags": [
     "Install"
    ],
    "operationId": "appsInstall",
    "summary": "This install",
    "security": [
     {
      "appKey": []
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Install"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/apps/install/deleted": {
   "post": {
    "tags": [
     "Install"
    ],
    "operationId": "appsInstallDeleted",
    "summary": "Confirm you deleted an uninstalled school's data",
    "description": "After uninstall the key is refused everywhere except here, for 30 days. Call it once you have deleted that school's data, within the days your manifest promised.",
    "security": [
     {
      "appKey": []
     }
    ],
    "responses": {
     "204": {
      "description": "Recorded"
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  },
  "/apps/me": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsMe",
    "summary": "The person using the app",
    "x-scopes": [
     "apps:me"
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Person"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/classes": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsClasses",
    "summary": "The person's classes",
    "description": "For a teacher: the classes they teach. For a parent: the classes of their own children whose guardian allowed the app.",
    "x-scopes": [
     "read:classes"
    ],
    "parameters": [
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/Class"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/classes/{class_ref}/students": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsClassStudents",
    "summary": "Students of one class whose guardians allowed the app",
    "x-scopes": [
     "read:students"
    ],
    "parameters": [
     {
      "name": "class_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/Student"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/children": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsChildren",
    "summary": "A parent's own children whose guardian allowed the app (coming)",
    "description": "**Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:students"
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 20,
           "items": {
            "$ref": "#/components/schemas/Student"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/schedule": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsSchedule",
    "summary": "The person's timetable for a range of days",
    "description": "A teacher's own lessons; a parent's children's lessons.",
    "x-scopes": [
     "read:schedule"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "At most 31 days after from (RANGE_TOO_WIDE)."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/Lesson"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/students/{student_ref}/attendance": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsAttendanceSummary",
    "summary": "A student's attendance for a range of days (coming)",
    "description": "**Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:attendance"
    ],
    "parameters": [
     {
      "name": "student_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "from",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "At most 92 days after from (RANGE_TOO_WIDE)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/AttendanceSummary"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/classes/{class_ref}/attendance/{date}": {
   "put": {
    "tags": [
     "Writes"
    ],
    "operationId": "appsSaveAttendance",
    "summary": "Mark attendance for one class and day, as the teacher",
    "x-scopes": [
     "write:attendance"
    ],
    "parameters": [
     {
      "name": "class_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 64
      },
      "description": "Send one so a retry never writes twice."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "marks"
        ],
        "properties": {
         "marks": {
          "type": "array",
          "minItems": 1,
          "maxItems": 200,
          "items": {
           "type": "object",
           "additionalProperties": false,
           "required": [
            "student_ref",
            "status"
           ],
           "properties": {
            "student_ref": {
             "type": "string",
             "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
             "maxLength": 44
            },
            "status": {
             "type": "string",
             "enum": [
              "present",
              "absent",
              "late",
              "excused"
             ]
            },
            "note": {
             "type": "string",
             "minLength": 1,
             "maxLength": 200,
             "description": "Optional; required when status is excused (MISSING_FIELD)."
            }
           },
           "if": {
            "properties": {
             "status": {
              "const": "excused"
             }
            }
           },
           "then": {
            "required": [
             "student_ref",
             "status",
             "note"
            ]
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "object",
           "additionalProperties": false,
           "required": [
            "saved"
           ],
           "properties": {
            "saved": {
             "type": "integer",
             "minimum": 0
            }
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StateConflict"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/students/{student_ref}/notes": {
   "get": {
    "tags": [
     "People and classes"
    ],
    "operationId": "appsNotes",
    "summary": "Notes to a student (coming)",
    "description": "**Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:notes"
    ],
    "parameters": [
     {
      "name": "student_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/NoteRead"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   },
   "post": {
    "tags": [
     "Writes"
    ],
    "operationId": "appsAddNote",
    "summary": "A short note to a student; the family sees it",
    "x-scopes": [
     "write:notes"
    ],
    "parameters": [
     {
      "name": "student_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 64
      },
      "description": "Send one so a retry never writes twice."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "text"
        ],
        "properties": {
         "text": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Note"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/live/sessions": {
   "get": {
    "tags": [
     "Live and recordings"
    ],
    "operationId": "appsLiveSessions",
    "summary": "Live Sabaq sessions of the person (first-party apps only) (coming)",
    "description": "A teacher's sessions, or a parent's children's sessions, for a range of days. **Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:live"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "At most 31 days after from (RANGE_TOO_WIDE)."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/LiveSession"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/live/sessions/{session_ref}/join": {
   "post": {
    "tags": [
     "Live and recordings"
    ],
    "operationId": "appsLiveJoin",
    "summary": "Open a session in saMas (first-party apps only) (coming)",
    "description": "Answers the saMas page to open for the person; the app never gets the audio room's pass. Consent, roster and time rules are Live Sabaq's own (LIVE_NO_CONSENT and the other LIVE_ codes). **Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:live"
    ],
    "parameters": [
     {
      "name": "session_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "object",
           "additionalProperties": false,
           "required": [
            "open_path"
           ],
           "properties": {
            "open_path": {
             "type": "string",
             "pattern": "^/",
             "maxLength": 200
            }
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StateConflict"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/recordings": {
   "get": {
    "tags": [
     "Live and recordings"
    ],
    "operationId": "appsRecordings",
    "summary": "Recordings the person may play (first-party apps only) (coming)",
    "description": "Each child's guardian must have allowed the app. Playing goes through the play link below, under Live Sabaq's rules: staff type a reason, every play is logged, guardians are told. **Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:recordings"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "At most 92 days after from (RANGE_TOO_WIDE)."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/Recording"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/recordings/{recording_ref}/play": {
   "get": {
    "tags": [
     "Live and recordings"
    ],
    "operationId": "appsRecordingPlay",
    "summary": "A 10-minute play link (first-party apps only) (coming)",
    "description": "**Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:recordings"
    ],
    "parameters": [
     {
      "name": "recording_ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
       "maxLength": 44
      }
     },
     {
      "name": "reason",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 200
      },
      "description": "Required for staff other than the teacher (LIVE_REASON_REQUIRED)."
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "object",
           "additionalProperties": false,
           "required": [
            "url",
            "expires_at"
           ],
           "properties": {
            "url": {
             "type": "string",
             "format": "uri"
            },
            "expires_at": {
             "type": "string",
             "format": "date-time"
            }
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/recitations": {
   "get": {
    "tags": [
     "Live and recordings"
    ],
    "operationId": "appsRecitations",
    "summary": "Recitations the person may hear (first-party apps only) (coming)",
    "description": "The madrasa's recitations (5.10) under the same rules as recordings. **Coming:** described so the first app can be designed; the shape may still change before it is built.",
    "x-scopes": [
     "read:recitations"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "At most 92 days after from (RANGE_TOO_WIDE)."
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 512
      },
      "description": "From page.next of the previous answer; valid 24 hours for the same route, filters and caller."
     },
     {
      "name": "size",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta",
          "page"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "type": "array",
           "maxItems": 100,
           "items": {
            "$ref": "#/components/schemas/Recording"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          },
          "page": {
           "$ref": "#/components/schemas/Page"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     },
     "400": {
      "$ref": "#/components/responses/Invalid"
     }
    },
    "security": [
     {
      "appKey": [],
      "userToken": []
     }
    ]
   }
  },
  "/apps/usage": {
   "get": {
    "tags": [
     "Install"
    ],
    "operationId": "appsUsage",
    "summary": "Your calls and limits at this school",
    "security": [
     {
      "appKey": []
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "Deprecation": {
        "$ref": "#/components/headers/Deprecation"
       },
       "Sunset": {
        "$ref": "#/components/headers/Sunset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "meta"
         ],
         "additionalProperties": false,
         "properties": {
          "data": {
           "$ref": "#/components/schemas/Usage"
          },
          "meta": {
           "$ref": "#/components/schemas/Meta"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthenticated"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "500": {
      "$ref": "#/components/responses/Internal"
     },
     "503": {
      "$ref": "#/components/responses/Unavailable"
     }
    }
   }
  }
 },
 "webhooks": {
  "app.installed": {
   "post": {
    "summary": "A school installed the app",
    "description": "Sent to your install address, signed with your registration secret (the install has no webhook secret yet). Carries a one-time install code; swap it with POST /apps/install/exchange.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/InstallEvent"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "app.uninstalled": {
   "post": {
    "summary": "A school uninstalled the app",
    "description": "Sent to your uninstall address, signed with your registration secret. Delete that school's data by delete_by, then call POST /apps/install/deleted.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/LifecycleEvent"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "app.paused": {
   "post": {
    "summary": "The school paused the app",
    "description": "Signed with the install's webhook secret. Calls answer APP_PAUSED until resumed.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/LifecycleEvent"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "app.resumed": {
   "post": {
    "summary": "The school resumed the app",
    "description": "Signed with the install's webhook secret.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/LifecycleEvent"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "attendance.saved": {
   "post": {
    "summary": "attendance.saved",
    "description": "Signed with the install's webhook secret; sent only when the manifest names it and a granted scope covers it.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "event",
         "delivery_id",
         "install_ref",
         "data"
        ],
        "properties": {
         "event": {
          "const": "attendance.saved"
         },
         "delivery_id": {
          "type": "string"
         },
         "install_ref": {
          "type": "string",
          "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
          "maxLength": 44
         },
         "data": {
          "type": "object",
          "description": "The event's fields, cut to the install's scopes; students as refs; nothing about a child without an allowed grant."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "student.enrolled": {
   "post": {
    "summary": "student.enrolled",
    "description": "Signed with the install's webhook secret; sent only when the manifest names it and a granted scope covers it.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "event",
         "delivery_id",
         "install_ref",
         "data"
        ],
        "properties": {
         "event": {
          "const": "student.enrolled"
         },
         "delivery_id": {
          "type": "string"
         },
         "install_ref": {
          "type": "string",
          "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
          "maxLength": 44
         },
         "data": {
          "type": "object",
          "description": "The event's fields, cut to the install's scopes; students as refs; nothing about a child without an allowed grant."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "student.updated": {
   "post": {
    "summary": "student.updated",
    "description": "Signed with the install's webhook secret; sent only when the manifest names it and a granted scope covers it.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "event",
         "delivery_id",
         "install_ref",
         "data"
        ],
        "properties": {
         "event": {
          "const": "student.updated"
         },
         "delivery_id": {
          "type": "string"
         },
         "install_ref": {
          "type": "string",
          "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
          "maxLength": 44
         },
         "data": {
          "type": "object",
          "description": "The event's fields, cut to the install's scopes; students as refs; nothing about a child without an allowed grant."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "lesson.assigned": {
   "post": {
    "summary": "lesson.assigned",
    "description": "Signed with the install's webhook secret; sent only when the manifest names it and a granted scope covers it.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "event",
         "delivery_id",
         "install_ref",
         "data"
        ],
        "properties": {
         "event": {
          "const": "lesson.assigned"
         },
         "delivery_id": {
          "type": "string"
         },
         "install_ref": {
          "type": "string",
          "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
          "maxLength": 44
         },
         "data": {
          "type": "object",
          "description": "The event's fields, cut to the install's scopes; students as refs; nothing about a child without an allowed grant."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  },
  "lesson.graded": {
   "post": {
    "summary": "lesson.graded",
    "description": "Signed with the install's webhook secret; sent only when the manifest names it and a granted scope covers it.",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "event",
         "delivery_id",
         "install_ref",
         "data"
        ],
        "properties": {
         "event": {
          "const": "lesson.graded"
         },
         "delivery_id": {
          "type": "string"
         },
         "install_ref": {
          "type": "string",
          "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
          "maxLength": 44
         },
         "data": {
          "type": "object",
          "description": "The event's fields, cut to the install's scopes; students as refs; nothing about a child without an allowed grant."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Received"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "appId": {
    "type": "apiKey",
    "in": "header",
    "name": "X-App-Id",
    "description": "Your app's id from the manifest."
   },
   "appSecret": {
    "type": "apiKey",
    "in": "header",
    "name": "X-App-Secret",
    "description": "The registration secret shown once when you registered the app. Server side only. Also signs app.installed and app.uninstalled deliveries."
   },
   "appKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-Api-Key",
    "description": "sk_app_ and 48 hex characters; one per install, for that school only; server side only."
   },
   "userToken": {
    "type": "http",
    "scheme": "bearer",
    "description": "From POST /apps/token; 15 minutes; bound to the install key that redeemed it."
   }
  },
  "headers": {
   "RateLimit-Limit": {
    "description": "Requests allowed in the window.",
    "schema": {
     "type": "integer",
     "minimum": 0
    }
   },
   "RateLimit-Remaining": {
    "description": "Requests left in the window. May be absent.",
    "required": false,
    "schema": {
     "type": "integer",
     "minimum": 0
    }
   },
   "RateLimit-Reset": {
    "description": "Seconds until the window resets.",
    "schema": {
     "type": "integer",
     "minimum": 0
    }
   },
   "Deprecation": {
    "description": "Present when the operation is deprecated (a date).",
    "required": false,
    "schema": {
     "type": "string"
    }
   },
   "Sunset": {
    "description": "Present with Deprecation: the date the operation stops, at least 90 days later.",
    "required": false,
    "schema": {
     "type": "string"
    }
   }
  },
  "schemas": {
   "Meta": {
    "type": "object",
    "required": [
     "request_id",
     "generated_at"
    ],
    "properties": {
     "request_id": {
      "type": "string"
     },
     "generated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Page": {
    "type": "object",
    "required": [
     "next",
     "size"
    ],
    "properties": {
     "next": {
      "type": [
       "string",
       "null"
      ]
     },
     "size": {
      "type": "integer"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "object",
      "description": "code is the contract (see the Error codes tab); message is for a person.",
      "required": [
       "code",
       "message",
       "hint",
       "field",
       "request_id",
       "retryable",
       "docs"
      ],
      "properties": {
       "code": {
        "type": "string"
       },
       "message": {
        "type": "string"
       },
       "hint": {
        "type": [
         "string",
         "null"
        ]
       },
       "field": {
        "type": [
         "string",
         "null"
        ]
       },
       "request_id": {
        "type": "string"
       },
       "retryable": {
        "type": "boolean"
       },
       "docs": {
        "type": "string",
        "format": "uri"
       }
      }
     }
    }
   },
   "InstallCredentials": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "install_ref",
     "key",
     "webhook_secret",
     "school",
     "scopes"
    ],
    "properties": {
     "install_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "key": {
      "type": "string",
      "pattern": "^sk_app_[0-9a-f]{48}$"
     },
     "webhook_secret": {
      "type": "string"
     },
     "school": {
      "$ref": "#/components/schemas/School"
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "School": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "name",
     "timezone",
     "languages",
     "parent_origins"
    ],
    "properties": {
     "name": {
      "type": "string",
      "maxLength": 120
     },
     "timezone": {
      "type": "string"
     },
     "languages": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "en",
        "ur"
       ]
      }
     },
     "parent_origins": {
      "type": "array",
      "maxItems": 2,
      "items": {
       "type": "string",
       "format": "uri"
      },
      "description": "The exact origins that frame your page for this school, for example https://mussarat.samas.school and https://admin.mussarat.samas.school. List them in your frame-ancestors."
     }
    }
   },
   "UserToken": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "token",
     "expires_at",
     "person",
     "school",
     "scopes"
    ],
    "properties": {
     "token": {
      "type": "string"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "person": {
      "$ref": "#/components/schemas/Person"
     },
     "school": {
      "$ref": "#/components/schemas/School"
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "Install": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "install_ref",
     "school",
     "state",
     "scopes",
     "scopes_pending",
     "trust"
    ],
    "properties": {
     "install_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "school": {
      "$ref": "#/components/schemas/School"
     },
     "state": {
      "type": "string",
      "enum": [
       "on",
       "paused",
       "suspended"
      ]
     },
     "scopes": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "scopes_pending": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "trust": {
      "type": "string",
      "enum": [
       "first_party",
       "partner"
      ]
     }
    }
   },
   "Person": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "ref",
     "first_name",
     "role"
    ],
    "properties": {
     "ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "first_name": {
      "type": "string",
      "maxLength": 60
     },
     "role": {
      "type": "string",
      "enum": [
       "teacher",
       "parent",
       "school_admin",
       "school_principal"
      ],
      "description": "Students come later, and only with an allowed guardian grant for that child."
     }
    }
   },
   "Class": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "class_ref",
     "name"
    ],
    "properties": {
     "class_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "name": {
      "type": "string",
      "maxLength": 80
     },
     "label": {
      "type": [
       "string",
       "null"
      ],
      "maxLength": 80,
      "description": "The school's word for it, for example halaqa."
     },
     "students": {
      "type": "integer",
      "minimum": 0
     }
    }
   },
   "Student": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "student_ref",
     "first_name"
    ],
    "properties": {
     "student_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "first_name": {
      "type": "string",
      "maxLength": 60
     },
     "class_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     }
    }
   },
   "Lesson": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "date",
     "starts",
     "ends",
     "class_ref",
     "title"
    ],
    "properties": {
     "date": {
      "type": "string",
      "format": "date"
     },
     "starts": {
      "type": "string",
      "pattern": "^[0-2][0-9]:[0-5][0-9]$"
     },
     "ends": {
      "type": "string",
      "pattern": "^[0-2][0-9]:[0-5][0-9]$"
     },
     "class_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "title": {
      "type": "string",
      "maxLength": 120
     },
     "live": {
      "type": "boolean"
     }
    }
   },
   "AttendanceSummary": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "student_ref",
     "from",
     "to",
     "present",
     "absent",
     "late",
     "excused",
     "days"
    ],
    "properties": {
     "student_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "from": {
      "type": "string",
      "format": "date"
     },
     "to": {
      "type": "string",
      "format": "date"
     },
     "present": {
      "type": "integer"
     },
     "absent": {
      "type": "integer"
     },
     "late": {
      "type": "integer"
     },
     "excused": {
      "type": "integer"
     },
     "days": {
      "type": "array",
      "maxItems": 92,
      "items": {
       "type": "object",
       "required": [
        "date",
        "status"
       ],
       "properties": {
        "date": {
         "type": "string",
         "format": "date"
        },
        "status": {
         "type": "string",
         "enum": [
          "present",
          "absent",
          "late",
          "excused"
         ]
        }
       }
      }
     }
    }
   },
   "Note": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "note_ref",
     "at"
    ],
    "properties": {
     "note_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "NoteRead": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "note_ref",
     "at",
     "text",
     "from"
    ],
    "properties": {
     "note_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "text": {
      "type": "string",
      "maxLength": 500
     },
     "from": {
      "type": "string",
      "maxLength": 80,
      "description": "The teacher's name as the school shows it."
     }
    }
   },
   "LiveSession": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "session_ref",
     "starts_at",
     "minutes",
     "status",
     "teacher"
    ],
    "properties": {
     "session_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "starts_at": {
      "type": "string",
      "format": "date-time"
     },
     "minutes": {
      "type": "integer"
     },
     "status": {
      "type": "string",
      "enum": [
       "scheduled",
       "live",
       "ended",
       "missed",
       "cancelled"
      ]
     },
     "teacher": {
      "type": "string",
      "maxLength": 80
     },
     "student_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "join_from": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Recording": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "recording_ref",
     "at",
     "seconds",
     "student_ref"
    ],
    "properties": {
     "recording_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "seconds": {
      "type": "integer"
     },
     "student_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "title": {
      "type": "string",
      "maxLength": 120
     }
    }
   },
   "Usage": {
    "type": "object",
    "additionalProperties": false,
    "required": [
     "calls_today",
     "calls_per_day",
     "per_minute"
    ],
    "properties": {
     "calls_today": {
      "type": "integer"
     },
     "calls_per_day": {
      "type": "integer"
     },
     "per_minute": {
      "type": "integer"
     },
     "cost_this_month_usd": {
      "type": [
       "string",
       "null"
      ]
     },
     "cost_cap_usd": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "InstallEvent": {
    "type": "object",
    "required": [
     "event",
     "delivery_id",
     "install_ref",
     "install_code",
     "expires_at"
    ],
    "properties": {
     "event": {
      "const": "app.installed"
     },
     "delivery_id": {
      "type": "string"
     },
     "install_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "install_code": {
      "type": "string"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "LifecycleEvent": {
    "type": "object",
    "required": [
     "event",
     "delivery_id",
     "install_ref"
    ],
    "properties": {
     "event": {
      "type": "string",
      "enum": [
       "app.uninstalled",
       "app.paused",
       "app.resumed"
      ]
     },
     "delivery_id": {
      "type": "string"
     },
     "install_ref": {
      "type": "string",
      "pattern": "^[a-z]{2,3}_[A-Za-z0-9]{12,40}$",
      "maxLength": 44
     },
     "delete_by": {
      "type": "string",
      "format": "date",
      "description": "app.uninstalled only."
     }
    }
   }
  },
  "responses": {
   "Invalid": {
    "description": "The request is not valid: UNKNOWN_FIELD, MISSING_FIELD, INVALID_TYPE, INVALID_ENUM, INVALID_DATE, TEXT_TOO_LONG, RANGE_TOO_WIDE, INVALID_PAGE_SIZE, INVALID_CURSOR.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Unauthenticated": {
    "description": "UNAUTHENTICATED (no or bad key or token), KEY_REVOKED (the key was rotated, or the app was uninstalled), TOKEN_EXPIRED (relaunch for a new user token).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Forbidden": {
    "description": "NOT_ALLOWED, SCOPE_MISSING, APP_PAUSED, APP_SUSPENDED, APP_SCOPE_NOT_ALLOWED.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "LaunchInvalid": {
    "description": "APP_LAUNCH_INVALID: the launch token was already used, has expired, or was made for another install.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "InstallCodeInvalid": {
    "description": "APP_INSTALL_CODE_INVALID: the install code was already used, has expired, or belongs to another app.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "NotFound": {
    "description": "NOT_FOUND, including a child whose guardian has not allowed the app, or has stopped sharing.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "StateConflict": {
    "description": "INVALID_STATE (for example a closed term, or a session not open yet), IDEMPOTENCY_MISMATCH, IDEMPOTENCY_IN_PROGRESS.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "RateLimited": {
    "description": "RATE_LIMITED (per minute, retryable) or APP_CAP_REACHED (the daily calls or monthly cost cap).",
    "headers": {
     "Retry-After": {
      "description": "Seconds to wait.",
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     },
     "RateLimit-Limit": {
      "$ref": "#/components/headers/RateLimit-Limit"
     },
     "RateLimit-Remaining": {
      "$ref": "#/components/headers/RateLimit-Remaining"
     },
     "RateLimit-Reset": {
      "$ref": "#/components/headers/RateLimit-Reset"
     },
     "Deprecation": {
      "$ref": "#/components/headers/Deprecation"
     },
     "Sunset": {
      "$ref": "#/components/headers/Sunset"
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Internal": {
    "description": "INTERNAL: something broke on our side; retry later with the same Idempotency-Key.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Unavailable": {
    "description": "MAINTENANCE or UPSTREAM_UNAVAILABLE (retryable).",
    "headers": {
     "Retry-After": {
      "description": "Seconds to wait, when known.",
      "schema": {
       "type": "integer",
       "minimum": 0
      }
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 }
}