{
  "openapi": "3.1.0",
  "info": {
    "title": "TRACE exchange API, /v2 (demonstration)",
    "version": "2026-12-01",
    "description": "ISERC → TRACE → (PPB) → NACOSTI. Every call uses a bearer token from POST /v1/token (one key per organisation, handed over privately). Examples are real answers from the sandbox, with tokens and keys masked. TRACE never approves or rejects: each organisation changes only its own records."
  },
  "servers": [
    {
      "url": "https://trace-api.apprenticecloud.com",
      "description": "Sandbox (the demonstration exchange)"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "Auth"
    },
    {
      "name": "Submit and update"
    },
    {
      "name": "Requests and documents"
    },
    {
      "name": "Read"
    },
    {
      "name": "Webhooks"
    }
  ],
  "paths": {
    "/v1/token": {
      "post": {
        "tags": [
          "Auth"
        ],
        "operationId": "getToken",
        "summary": "Get a token (client credentials)",
        "security": [],
        "description": "The client id and secret in the form, or in Basic auth (then the form carries only grant_type). The token works for 900 seconds.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type"
                ],
                "properties": {
                  "grant_type": {
                    "const": "client_credentials"
                  },
                  "client_id": {
                    "type": "string"
                  },
                  "client_secret": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Token"
                },
                "examples": {
                  "token": {
                    "summary": "token (KEMRI, captured)",
                    "value": {
                      "access_token": "<token from POST /v1/token>",
                      "token_type": "Bearer",
                      "expires_in": 900
                    }
                  },
                  "token_basic": {
                    "summary": "token_basic (KEMRI, captured)",
                    "value": {
                      "access_token": "<token from POST /v1/token>",
                      "token_type": "Bearer",
                      "expires_in": 900
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "grant_type is not client_credentials: {\"error\": \"unsupported_grant_type\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                }
              }
            }
          },
          "401": {
            "description": "Unknown client, wrong secret, revoked key: {\"error\": \"invalid_client\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "token_wrong": {
                    "summary": "token_wrong (KEMRI, captured)",
                    "value": {
                      "error": "invalid_client"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/applications": {
      "post": {
        "tags": [
          "Submit and update"
        ],
        "operationId": "submitApplication",
        "summary": "Submit an application (an ISERC)",
        "description": "TRACE checks every required document is there and fits (a PDF, a sha256, 1 byte to 20 MB, the current template if one is named). Accepted: the Application ID, once and for good; NACOSTI is told at once (application.created).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Submission"
              },
              "examples": {
                "submit_accepted": {
                  "summary": "Complete: TRACE issues the Application ID and tells NACOSTI (application.created). (KEMRI)",
                  "value": {
                    "event_id": "devd4fcad-k4",
                    "source_ref": "KEMRI/SERU/2026/DEVD4FCAD",
                    "study": {
                      "title": "Malaria vaccine uptake among children under five in Kisumu County",
                      "type": "non_clinical",
                      "sites": [
                        "Kisumu"
                      ],
                      "starts_on": "2027-01-15",
                      "ends_on": "2027-12-15"
                    },
                    "investigator": {
                      "name": "Dr. Achieng Otieno",
                      "institution": "Maseno University"
                    },
                    "documents": [
                      {
                        "kind": "protocol",
                        "filename": "protocol.pdf",
                        "sha256": "646d0571e44e0f99d8cb46246fe7a7fa5057b05e0cdf82203576b335c8c6b935",
                        "bytes": 192156,
                        "template": "NACOSTI-PROTOCOL-2026"
                      },
                      {
                        "kind": "affiliation_letter",
                        "filename": "affiliation-letter.pdf",
                        "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                        "bytes": 202286
                      }
                    ]
                  }
                },
                "submit_clinical_trial": {
                  "summary": "A clinical trial needs four documents. (MTRH)",
                  "value": {
                    "event_id": "devd4fcad-m1",
                    "source_ref": "MTRH/IREC/2026/DEVD4FCAD",
                    "study": {
                      "title": "Phase III trial of a single-dose sickle cell gene therapy in adolescents",
                      "type": "clinical_trial",
                      "sites": [
                        "Eldoret",
                        "Kakamega"
                      ],
                      "starts_on": "2027-03-01",
                      "ends_on": "2029-02-28"
                    },
                    "investigator": {
                      "name": "Prof. Kiprono Chelimo",
                      "institution": "Moi University"
                    },
                    "documents": [
                      {
                        "kind": "protocol",
                        "filename": "protocol-v1.pdf",
                        "sha256": "78f43bd46120077afc2348e0f3bb11f0136ae80a711ce46cb2593a51696e67cc",
                        "bytes": 195195
                      },
                      {
                        "kind": "affiliation_letter",
                        "filename": "affiliation-letter.pdf",
                        "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                        "bytes": 202286
                      },
                      {
                        "kind": "informed_consent_form",
                        "filename": "consent-form.pdf",
                        "sha256": "a04aa0a557c054c2e72c5a1657e0212ecd46c8d6fe21dca9ab6e1a687e5653a1",
                        "bytes": 196208
                      },
                      {
                        "kind": "investigators_brochure",
                        "filename": "brochure.pdf",
                        "sha256": "a6d0ab662a3720d139371550dc9b97322169744bc14e13c0caab392c4c3b45b9",
                        "bytes": 192156
                      }
                    ]
                  }
                },
                "submit_incomplete": {
                  "summary": "The affiliation letter is missing. (KEMRI)",
                  "value": {
                    "event_id": "devd4fcad-k1",
                    "source_ref": "KEMRI/SERU/2026/DEVD4FCAD",
                    "study": {
                      "title": "Malaria vaccine uptake among children under five in Kisumu County",
                      "type": "non_clinical",
                      "sites": [
                        "Kisumu"
                      ],
                      "starts_on": "2027-01-15",
                      "ends_on": "2027-12-15"
                    },
                    "investigator": {
                      "name": "Dr. Achieng Otieno",
                      "institution": "Maseno University"
                    },
                    "documents": [
                      {
                        "kind": "protocol",
                        "filename": "protocol.pdf",
                        "sha256": "646d0571e44e0f99d8cb46246fe7a7fa5057b05e0cdf82203576b335c8c6b935",
                        "bytes": 192156
                      }
                    ]
                  }
                },
                "submit_wrong_document": {
                  "summary": "A Word file, and a letter on last year's template. (KEMRI)",
                  "value": {
                    "event_id": "devd4fcad-k2",
                    "source_ref": "KEMRI/SERU/2026/DEVD4FCAD",
                    "study": {
                      "title": "Malaria vaccine uptake among children under five in Kisumu County",
                      "type": "non_clinical",
                      "sites": [
                        "Kisumu"
                      ],
                      "starts_on": "2027-01-15",
                      "ends_on": "2027-12-15"
                    },
                    "investigator": {
                      "name": "Dr. Achieng Otieno",
                      "institution": "Maseno University"
                    },
                    "documents": [
                      {
                        "kind": "protocol",
                        "filename": "protocol.docx",
                        "sha256": "3fd6c76d2d23bbb8ae942ca93d8a0ac0fffdb726518396dd15f11615374b49ab",
                        "bytes": 193169
                      },
                      {
                        "kind": "affiliation_letter",
                        "filename": "affiliation-letter.pdf",
                        "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                        "bytes": 202286,
                        "template": "NACOSTI-AFFILIATION-2024"
                      }
                    ]
                  }
                },
                "submit_personal_data": {
                  "summary": "Personal details sent by mistake: accepted, and the extra fields are dropped, never stored. (KEMRI)",
                  "value": {
                    "event_id": "devd4fcad-k6",
                    "source_ref": "KEMRI/SERU/2026/DEVD4FCAD-P",
                    "study": {
                      "title": "Malaria vaccine uptake among children under five in Kisumu County",
                      "type": "non_clinical",
                      "sites": [
                        "Kisumu"
                      ],
                      "starts_on": "2027-01-15",
                      "ends_on": "2027-12-15"
                    },
                    "investigator": {
                      "name": "Dr. Achieng Otieno",
                      "institution": "Maseno University",
                      "national_id": "12345678",
                      "phone": "+254700000000",
                      "date_of_birth": "1980-01-01"
                    },
                    "documents": [
                      {
                        "kind": "protocol",
                        "filename": "protocol.pdf",
                        "sha256": "646d0571e44e0f99d8cb46246fe7a7fa5057b05e0cdf82203576b335c8c6b935",
                        "bytes": 192156
                      },
                      {
                        "kind": "affiliation_letter",
                        "filename": "affiliation-letter.pdf",
                        "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                        "bytes": 202286
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same event_id again: the first answer, with result duplicate. A first answer that was a 422 comes back as the same 422.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "submit_duplicate": {
                    "summary": "The same event_id again: the first answer, marked duplicate. Nothing new is created. (KEMRI, captured)",
                    "value": {
                      "result": "duplicate",
                      "application_id": "KE-KEMRI-2026-000043-3",
                      "route": "non_clinical",
                      "stage": "ethics_review"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Accepted: the Application ID, the route and the stage.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "submit_accepted": {
                    "summary": "Complete: TRACE issues the Application ID and tells NACOSTI (application.created). (KEMRI, captured)",
                    "value": {
                      "result": "accepted",
                      "application_id": "KE-KEMRI-2026-000043-3",
                      "route": "non_clinical",
                      "stage": "ethics_review"
                    }
                  },
                  "submit_clinical_trial": {
                    "summary": "A clinical trial needs four documents. (MTRH, captured)",
                    "value": {
                      "result": "accepted",
                      "application_id": "KE-MTRH-2026-000061-5",
                      "route": "clinical_trial",
                      "stage": "ethics_review"
                    }
                  },
                  "submit_personal_data": {
                    "summary": "Personal details sent by mistake: accepted, and the extra fields are dropped, never stored. (KEMRI, captured)",
                    "value": {
                      "result": "accepted",
                      "application_id": "KE-KEMRI-2026-000044-1",
                      "route": "non_clinical",
                      "stage": "ethics_review"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Not an ISERC: not_allowed.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                },
                "examples": {
                  "submit_not_allowed": {
                    "summary": "Only an ISERC submits. (PPB, captured)",
                    "value": {
                      "result": "not_allowed",
                      "why": "only an ISERC submits applications"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "incomplete (missing or unfit documents: nothing is created or sent on) or rejected (fields, or a source_ref already used).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Incomplete"
                    },
                    {
                      "$ref": "#/components/schemas/Rejected"
                    }
                  ]
                },
                "examples": {
                  "submit_incomplete": {
                    "summary": "The affiliation letter is missing. (KEMRI, captured)",
                    "value": {
                      "result": "incomplete",
                      "missing": [
                        "affiliation_letter"
                      ],
                      "wrong": [],
                      "message": "Nothing was created or sent on. Send the application again with every document."
                    }
                  },
                  "submit_wrong_document": {
                    "summary": "A Word file, and a letter on last year's template. (KEMRI, captured)",
                    "value": {
                      "result": "incomplete",
                      "missing": [],
                      "wrong": [
                        {
                          "kind": "protocol",
                          "filename": "protocol.docx",
                          "why": "must be a PDF"
                        },
                        {
                          "kind": "affiliation_letter",
                          "filename": "affiliation-letter.pdf",
                          "why": "template NACOSTI-AFFILIATION-2024 is out of date; use NACOSTI-AFFILIATION-2026"
                        }
                      ],
                      "message": "Nothing was created or sent on. Send the application again with every document."
                    }
                  },
                  "submit_rejected": {
                    "summary": "No title, a date not in YYYY-MM-DD, no institution. (KEMRI, captured)",
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "study.title",
                        "study.starts_on",
                        "investigator.institution"
                      ]
                    }
                  },
                  "submit_same_source_ref": {
                    "summary": "A new event_id with a source_ref already used. (KEMRI, captured)",
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "source_ref"
                      ],
                      "why": "already submitted under another event_id"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/applications/{application_id}/documents": {
      "post": {
        "tags": [
          "Submit and update"
        ],
        "operationId": "addDocumentVersion",
        "summary": "Add a document version",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          }
        ],
        "description": "The ISERC adds to its own application (never a PPB kind); PPB adds while it holds ppb_review. After ethics approval a new version is kept but does not count (counts: false, why). Nobody adds after licensed or rejected.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentVersion"
              },
              "examples": {
                "document_new_version": {
                  "summary": "Version 2 counts; version 1 is kept as history. (MTRH)",
                  "value": {
                    "event_id": "devd4fcad-m3",
                    "kind": "protocol",
                    "filename": "protocol-v2.pdf",
                    "sha256": "194077f5647a40a8a6d13dfa48c746182d08a3645726a634254b06faf07d624c",
                    "bytes": 195195
                  }
                },
                "document_locked": {
                  "summary": "After approval: kept, but it does not count. (MTRH)",
                  "value": {
                    "event_id": "devd4fcad-m6",
                    "kind": "protocol",
                    "filename": "protocol-v3.pdf",
                    "sha256": "d040e5127c87262a53ba613154ba2a84e259b70b2878f1956fd17b72aad15ba6",
                    "bytes": 195195
                  }
                },
                "document_ppb": {
                  "summary": "PPB adds its own documents while it holds the stage. (PPB)",
                  "value": {
                    "event_id": "devd4fcad-p1",
                    "kind": "ppb_application_form",
                    "filename": "ppb-application-form.pdf",
                    "sha256": "9e93244427056e452b66af561b0b6539be98581895cd38f644855fe764b0a5ef",
                    "bytes": 204312
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same event_id again (duplicate).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {}
              }
            }
          },
          "201": {
            "description": "Kept, with its version and whether it counts.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "document_new_version": {
                    "summary": "Version 2 counts; version 1 is kept as history. (MTRH, captured)",
                    "value": {
                      "result": "accepted",
                      "document_id": "7372e628-a6f5-42d1-b6c9-03a88193c316",
                      "kind": "protocol",
                      "version": 2,
                      "counts": true
                    }
                  },
                  "document_locked": {
                    "summary": "After approval: kept, but it does not count. (MTRH, captured)",
                    "value": {
                      "result": "accepted",
                      "document_id": "e15b9089-5a1c-4db2-b664-02c6bf7fc8e2",
                      "kind": "protocol",
                      "version": 3,
                      "counts": false,
                      "why": "approved version 2 is locked; this one is kept but does not count"
                    }
                  },
                  "document_ppb": {
                    "summary": "PPB adds its own documents while it holds the stage. (PPB, captured)",
                    "value": {
                      "result": "accepted",
                      "document_id": "0794103c-6545-4c9b-a5e1-36a10615aac0",
                      "kind": "ppb_application_form",
                      "version": 1,
                      "counts": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "not_owner: this organisation cannot add documents now (or an ISERC sent a PPB kind).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                },
                "examples": {
                  "event_after_end": {
                    "summary": "Licensed: nobody adds documents any more. (MTRH, captured)",
                    "value": {
                      "result": "not_owner",
                      "why": "this organisation cannot add documents to this application now"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not this organisation's to see.",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {}
              }
            }
          },
          "422": {
            "description": "rejected (no event_id) or incomplete (the document doesn't fit; see wrong).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Incomplete"
                    },
                    {
                      "$ref": "#/components/schemas/Rejected"
                    }
                  ]
                },
                "examples": {}
              }
            }
          }
        }
      }
    },
    "/v2/applications/{application_id}/events": {
      "post": {
        "tags": [
          "Submit and update"
        ],
        "operationId": "recordEvent",
        "summary": "Record a decision or a request for changes (the stage's owner)",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              },
              "examples": {
                "event_changes_requested": {
                  "summary": "The stage stays; TRACE waits on the applicant. (MTRH)",
                  "value": {
                    "event_id": "devd4fcad-m2",
                    "type": "ethics.changes_requested",
                    "reference": "MTRH/IREC/CR/1",
                    "note": "Revise the dosing section."
                  }
                },
                "event_ethics_approved": {
                  "summary": "Approval locks the latest version of each document and, for a trial, routes to PPB. (MTRH)",
                  "value": {
                    "event_id": "devd4fcad-m5",
                    "type": "ethics.approved",
                    "reference": "MTRH/IREC/2026/0412",
                    "decided_on": "2026-12-02"
                  }
                },
                "event_ppb_authorised": {
                  "summary": "Routes to NACOSTI; ending within 30 days, so TRACE also sends authorisation.expiring. (PPB)",
                  "value": {
                    "event_id": "devd4fcad-p3",
                    "type": "ppb.authorised",
                    "reference": "PPB/CT/2026/0103",
                    "decided_on": "2026-12-02",
                    "valid_until": "2026-12-27"
                  }
                },
                "event_licence_issued": {
                  "summary": "The end of the pipeline: licence.decided goes out. (NACOSTI)",
                  "value": {
                    "event_id": "devd4fcad-n1",
                    "type": "licence.issued",
                    "reference": "NACOSTI/P/26/0412",
                    "decided_on": "2026-12-02"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted: the stage now, and where it was routed.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "event_changes_requested": {
                    "summary": "The stage stays; TRACE waits on the applicant. (MTRH, captured)",
                    "value": {
                      "result": "accepted",
                      "request_id": "4a7646b6-9f31-448c-92dc-5c663d8c4343",
                      "stage": "ethics_review",
                      "waiting_on": "applicant",
                      "requested_from": "applicant"
                    }
                  },
                  "event_ethics_approved": {
                    "summary": "Approval locks the latest version of each document and, for a trial, routes to PPB. (MTRH, captured)",
                    "value": {
                      "result": "accepted",
                      "stage": "ppb_review",
                      "routed_to": "PPB"
                    }
                  },
                  "event_ppb_authorised": {
                    "summary": "Routes to NACOSTI; ending within 30 days, so TRACE also sends authorisation.expiring. (PPB, captured)",
                    "value": {
                      "result": "accepted",
                      "stage": "nacosti_review",
                      "routed_to": "NACOSTI"
                    }
                  },
                  "event_licence_issued": {
                    "summary": "The end of the pipeline: licence.decided goes out. (NACOSTI, captured)",
                    "value": {
                      "result": "accepted",
                      "stage": "licensed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "not_owner: the current stage belongs to another organisation.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                },
                "examples": {
                  "event_not_owner": {
                    "summary": "NACOSTI may not decide while the ISERC holds the stage. (NACOSTI, captured)",
                    "value": {
                      "result": "not_owner",
                      "stage": "ethics_review",
                      "why": "the ethics review stage belongs to ISERC"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not this organisation's to see.",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {}
              }
            }
          },
          "422": {
            "description": "rejected: a missing event_id, an unknown type, or ppb.authorised without valid_until.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rejected"
                },
                "examples": {
                  "event_rejected_fields": {
                    "summary": "An unknown type. (MTRH, captured)",
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "type"
                      ]
                    }
                  },
                  "event_missing_valid_until": {
                    "summary": "An authorisation needs valid_until. (PPB, captured)",
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "valid_until"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/applications/{application_id}": {
      "get": {
        "tags": [
          "Read"
        ],
        "operationId": "readApplication",
        "summary": "Read one application",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The package, the documents with every version and which counts, the timeline (each stage, its holder, days and flag) and, for NACOSTI and the ISERC that submitted it, the history of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Application"
                },
                "examples": {
                  "read_nacosti": {
                    "summary": "NACOSTI sees every application, with its history of calls. (NACOSTI, captured)",
                    "value": {
                      "application_id": "KE-MTRH-2026-000061-5",
                      "source": "MTRH",
                      "source_ref": "MTRH/IREC/2026/DEVD4FCAD",
                      "route": "clinical_trial",
                      "stage": "licensed",
                      "study": {
                        "title": "Phase III trial of a single-dose sickle cell gene therapy in adolescents",
                        "type": "clinical_trial",
                        "sites": [
                          "Eldoret",
                          "Kakamega"
                        ],
                        "starts_on": "2027-03-01",
                        "ends_on": "2029-02-28"
                      },
                      "investigator": {
                        "name": "Prof. Kiprono Chelimo",
                        "institution": "Moi University"
                      },
                      "documents": [
                        {
                          "kind": "affiliation_letter",
                          "label": "Affiliation letter",
                          "versions": [
                            {
                              "document_id": "e4b87d16-db67-422b-8264-3ed09d8e1048",
                              "version": 1,
                              "filename": "affiliation-letter.pdf",
                              "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                              "bytes": 202286,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "informed_consent_form",
                          "label": "Informed consent form",
                          "versions": [
                            {
                              "document_id": "362bc6dc-dcf9-4568-bb16-6d2edccc36e3",
                              "version": 1,
                              "filename": "consent-form.pdf",
                              "sha256": "a04aa0a557c054c2e72c5a1657e0212ecd46c8d6fe21dca9ab6e1a687e5653a1",
                              "bytes": 196208,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "investigators_brochure",
                          "label": "Investigator's brochure",
                          "versions": [
                            {
                              "document_id": "f41c5686-4760-46d3-9a03-5ac31433c987",
                              "version": 1,
                              "filename": "brochure.pdf",
                              "sha256": "a6d0ab662a3720d139371550dc9b97322169744bc14e13c0caab392c4c3b45b9",
                              "bytes": 192156,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "ppb_application_form",
                          "label": "PPB application form",
                          "versions": [
                            {
                              "document_id": "0794103c-6545-4c9b-a5e1-36a10615aac0",
                              "version": 1,
                              "filename": "ppb-application-form.pdf",
                              "sha256": "9e93244427056e452b66af561b0b6539be98581895cd38f644855fe764b0a5ef",
                              "bytes": 204312,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "PPB",
                              "at": "2026-12-02T12:21:18.467612+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "protocol",
                          "label": "Protocol",
                          "versions": [
                            {
                              "document_id": "05602b20-2241-4bf0-8d62-ef7847c2a522",
                              "version": 1,
                              "filename": "protocol-v1.pdf",
                              "sha256": "78f43bd46120077afc2348e0f3bb11f0136ae80a711ce46cb2593a51696e67cc",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            },
                            {
                              "document_id": "7372e628-a6f5-42d1-b6c9-03a88193c316",
                              "version": 2,
                              "filename": "protocol-v2.pdf",
                              "sha256": "194077f5647a40a8a6d13dfa48c746182d08a3645726a634254b06faf07d624c",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:21:04.473575+00:00"
                            },
                            {
                              "document_id": "e15b9089-5a1c-4db2-b664-02c6bf7fc8e2",
                              "version": 3,
                              "filename": "protocol-v3.pdf",
                              "sha256": "d040e5127c87262a53ba613154ba2a84e259b70b2878f1956fd17b72aad15ba6",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:21:11.873156+00:00",
                              "note": "approved version 2 is locked; this one is kept but does not count"
                            }
                          ],
                          "counts": 2
                        }
                      ],
                      "decisions": {
                        "ethics": "MTRH/IREC/2026/0412",
                        "ppb": "PPB/CT/2026/0103",
                        "licence": "NACOSTI/P/26/0412"
                      },
                      "ppb_valid_until": "2026-12-27",
                      "waiting_on": "reviewer",
                      "holder": "",
                      "days_in_stage": 0,
                      "flag": "done",
                      "expiring": false,
                      "timeline": [
                        {
                          "stage": "ethics_review",
                          "holder": "ISERC",
                          "started_at": "2026-12-02T12:20:57.851253+00:00",
                          "ended_at": "2026-12-02T12:21:08.407690+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "ppb_review",
                          "holder": "PPB",
                          "started_at": "2026-12-02T12:21:08.407690+00:00",
                          "ended_at": "2026-12-02T12:21:21.898730+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "nacosti_review",
                          "holder": "NACOSTI",
                          "started_at": "2026-12-02T12:21:21.898730+00:00",
                          "ended_at": "2026-12-02T12:21:25.819214+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "licensed",
                          "holder": "",
                          "started_at": "2026-12-02T12:21:25.819214+00:00",
                          "ended_at": null,
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "done"
                        }
                      ],
                      "history": [
                        {
                          "type": "submitted",
                          "by": "MTRH",
                          "at": "2026-12-02T12:20:57.851253+00:00",
                          "stage_to": "ethics_review",
                          "correlation_id": "5094c57c56c24f30b92c21562b1a0d13"
                        },
                        {
                          "type": "information.requested",
                          "by": "MTRH",
                          "at": "2026-12-02T12:21:01.167051+00:00",
                          "stage_to": null,
                          "correlation_id": "ce15962842f242b88f1b76612de65a6d"
                        },
                        {
                          "type": "document.added",
                          "by": "MTRH",
                          "at": "2026-12-02T12:21:04.478242+00:00",
                          "stage_to": null,
                          "correlation_id": "04a295c6fd7745e99b88f284cdced057"
                        },
                        {
                          "type": "event.refused",
                          "by": "NACOSTI",
                          "at": "2026-12-02T12:21:08.136877+00:00",
                          "stage_to": null,
                          "correlation_id": "a5cec4419d7141c49f107d431014f12a"
                        }
                      ],
                      "requests": [
                        {
                          "request_id": "4a7646b6-9f31-448c-92dc-5c663d8c4343",
                          "requested_by": "MTRH",
                          "requested_from": "applicant",
                          "audience": "applicant",
                          "note": "Revise the dosing section.",
                          "stage": "ethics_review",
                          "state": "closed",
                          "requested_at": "2026-12-02T12:21:01.158542+00:00",
                          "response_due_at": null
                        }
                      ]
                    }
                  },
                  "read_ppb": {
                    "summary": "PPB sees the trials sent to it: the package and the timeline, not the history. (PPB, captured)",
                    "value": {
                      "application_id": "KE-MTRH-2026-000061-5",
                      "source": "MTRH",
                      "source_ref": "MTRH/IREC/2026/DEVD4FCAD",
                      "route": "clinical_trial",
                      "stage": "licensed",
                      "study": {
                        "title": "Phase III trial of a single-dose sickle cell gene therapy in adolescents",
                        "type": "clinical_trial",
                        "sites": [
                          "Eldoret",
                          "Kakamega"
                        ],
                        "starts_on": "2027-03-01",
                        "ends_on": "2029-02-28"
                      },
                      "investigator": {
                        "name": "Prof. Kiprono Chelimo",
                        "institution": "Moi University"
                      },
                      "documents": [
                        {
                          "kind": "affiliation_letter",
                          "label": "Affiliation letter",
                          "versions": [
                            {
                              "document_id": "e4b87d16-db67-422b-8264-3ed09d8e1048",
                              "version": 1,
                              "filename": "affiliation-letter.pdf",
                              "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                              "bytes": 202286,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "informed_consent_form",
                          "label": "Informed consent form",
                          "versions": [
                            {
                              "document_id": "362bc6dc-dcf9-4568-bb16-6d2edccc36e3",
                              "version": 1,
                              "filename": "consent-form.pdf",
                              "sha256": "a04aa0a557c054c2e72c5a1657e0212ecd46c8d6fe21dca9ab6e1a687e5653a1",
                              "bytes": 196208,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "investigators_brochure",
                          "label": "Investigator's brochure",
                          "versions": [
                            {
                              "document_id": "f41c5686-4760-46d3-9a03-5ac31433c987",
                              "version": 1,
                              "filename": "brochure.pdf",
                              "sha256": "a6d0ab662a3720d139371550dc9b97322169744bc14e13c0caab392c4c3b45b9",
                              "bytes": 192156,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "ppb_application_form",
                          "label": "PPB application form",
                          "versions": [
                            {
                              "document_id": "0794103c-6545-4c9b-a5e1-36a10615aac0",
                              "version": 1,
                              "filename": "ppb-application-form.pdf",
                              "sha256": "9e93244427056e452b66af561b0b6539be98581895cd38f644855fe764b0a5ef",
                              "bytes": 204312,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "PPB",
                              "at": "2026-12-02T12:21:18.467612+00:00"
                            }
                          ],
                          "counts": 1
                        },
                        {
                          "kind": "protocol",
                          "label": "Protocol",
                          "versions": [
                            {
                              "document_id": "05602b20-2241-4bf0-8d62-ef7847c2a522",
                              "version": 1,
                              "filename": "protocol-v1.pdf",
                              "sha256": "78f43bd46120077afc2348e0f3bb11f0136ae80a711ce46cb2593a51696e67cc",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:20:57.729239+00:00"
                            },
                            {
                              "document_id": "7372e628-a6f5-42d1-b6c9-03a88193c316",
                              "version": 2,
                              "filename": "protocol-v2.pdf",
                              "sha256": "194077f5647a40a8a6d13dfa48c746182d08a3645726a634254b06faf07d624c",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": true,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:21:04.473575+00:00"
                            },
                            {
                              "document_id": "e15b9089-5a1c-4db2-b664-02c6bf7fc8e2",
                              "version": 3,
                              "filename": "protocol-v3.pdf",
                              "sha256": "d040e5127c87262a53ba613154ba2a84e259b70b2878f1956fd17b72aad15ba6",
                              "bytes": 195195,
                              "file": "manifest_only",
                              "approved": false,
                              "added_by": "MTRH",
                              "at": "2026-12-02T12:21:11.873156+00:00",
                              "note": "approved version 2 is locked; this one is kept but does not count"
                            }
                          ],
                          "counts": 2
                        }
                      ],
                      "decisions": {
                        "ethics": "MTRH/IREC/2026/0412",
                        "ppb": "PPB/CT/2026/0103",
                        "licence": "NACOSTI/P/26/0412"
                      },
                      "ppb_valid_until": "2026-12-27",
                      "waiting_on": "reviewer",
                      "holder": "",
                      "days_in_stage": 0,
                      "flag": "done",
                      "expiring": false,
                      "timeline": [
                        {
                          "stage": "ethics_review",
                          "holder": "ISERC",
                          "started_at": "2026-12-02T12:20:57.851253+00:00",
                          "ended_at": "2026-12-02T12:21:08.407690+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "ppb_review",
                          "holder": "PPB",
                          "started_at": "2026-12-02T12:21:08.407690+00:00",
                          "ended_at": "2026-12-02T12:21:21.898730+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "nacosti_review",
                          "holder": "NACOSTI",
                          "started_at": "2026-12-02T12:21:21.898730+00:00",
                          "ended_at": "2026-12-02T12:21:25.819214+00:00",
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "on_time"
                        },
                        {
                          "stage": "licensed",
                          "holder": "",
                          "started_at": "2026-12-02T12:21:25.819214+00:00",
                          "ended_at": null,
                          "days": 0,
                          "waiting_days": 0,
                          "reviewer_days": 0,
                          "flag": "done"
                        }
                      ],
                      "requests": []
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not this organisation's to see.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {
                  "read_other_iserc": {
                    "summary": "Another ISERC's application: not found. (KEMRI, captured)",
                    "value": {
                      "result": "not_found"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/pipeline": {
      "get": {
        "tags": [
          "Read"
        ],
        "operationId": "readPipeline",
        "summary": "Every application this organisation may see",
        "responses": {
          "200": {
            "description": "Each application's stage, holder, days in stage and flag (on_time; amber at 14 days; red at 30; done when licensed or rejected), expiring when a PPB authorisation ends within 30 days, and the counts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pipeline"
                },
                "examples": {
                  "pipeline": {
                    "summary": "Every application NACOSTI may see. Shortened here to three rows, one of them waiting after a request. (NACOSTI, captured)",
                    "value": {
                      "thresholds": {
                        "amber_days": 14,
                        "red_days": 30,
                        "expiring_days": 30
                      },
                      "counts": {
                        "ethics_review": 52,
                        "ppb_review": 3,
                        "nacosti_review": 22,
                        "licensed": 27,
                        "rejected": 12
                      },
                      "red": 3,
                      "amber": 2,
                      "expiring": 12,
                      "applications": [
                        {
                          "application_id": "KE-KEMRI-2026-000005-2",
                          "source": "KEMRI",
                          "route": "clinical_trial",
                          "title": "Dose-finding study of a monoclonal antibody against RSV in infants",
                          "stage": "licensed",
                          "holder": "",
                          "waiting_on": "reviewer",
                          "days_in_stage": 1.1,
                          "flag": "done",
                          "waiting_days": 0,
                          "expiring": false,
                          "ppb_valid_until": "2027-09-27",
                          "total_days": 71.1
                        },
                        {
                          "application_id": "KE-MTRH-2026-000004-5",
                          "source": "MTRH",
                          "route": "clinical_trial",
                          "title": "Safety of a new artemisinin combination in pregnancy, second trimester",
                          "stage": "nacosti_review",
                          "holder": "NACOSTI",
                          "waiting_on": "reviewer",
                          "days_in_stage": 17.1,
                          "flag": "amber",
                          "waiting_days": 0,
                          "expiring": true,
                          "ppb_valid_until": "2026-12-13",
                          "total_days": 57.1
                        },
                        {
                          "application_id": "KE-KEMRI-2026-000046-6",
                          "source": "KEMRI",
                          "route": "non_clinical",
                          "title": "Malaria vaccine uptake among children under five in Kisumu County",
                          "stage": "nacosti_review",
                          "holder": "NACOSTI",
                          "waiting_on": "reviewer",
                          "days_in_stage": 0,
                          "flag": "on_time",
                          "waiting_days": 0,
                          "expiring": false,
                          "ppb_valid_until": null,
                          "total_days": 0
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Not a TRACE member: not_allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                }
              }
            }
          }
        }
      }
    },
    "/v2/webhooks": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "registerWebhooks",
        "summary": "Say where TRACE sends this organisation's webhooks",
        "description": "One subscription per organisation and environment. The secret is returned once; registering again replaces the subscription and the secret.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Subscription"
              },
              "examples": {
                "register": {
                  "summary": "Every event",
                  "value": {
                    "url": "https://your-system.example/trace/webhooks"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registered. Keep the secret: it is not shown again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionAnswer"
                },
                "examples": {
                  "registered": {
                    "summary": "Shape from the code (not replayed: it would replace a demo partner's secret)",
                    "value": {
                      "result": "accepted",
                      "url": "https://your-system.example/trace/webhooks",
                      "events": [
                        "application.created",
                        "document.version_added",
                        "stage.changed",
                        "package.sent_to_ppb",
                        "package.sent_to_nacosti",
                        "authorisation.expiring",
                        "stage.overdue",
                        "licence.decided",
                        "information.requested",
                        "information.responded"
                      ],
                      "secret": "whsec_<32 hex characters, shown once>"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "The url is not http(s), or not a TRACE member.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rejected"
                },
                "examples": {
                  "bad_url": {
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "url"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/applications/{application_id}/requests": {
      "post": {
        "tags": [
          "Requests and documents"
        ],
        "operationId": "openRequest",
        "summary": "Ask the source ISERC or the applicant (the stage's holder)",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          }
        ],
        "description": "The stage does not move; waiting_on becomes the recipient, so the clock counts the time as waiting, not review. information.requested goes, with the note, only to the source ISERC and the requester.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RequestIn"
              },
              "examples": {
                "request_to_iserc": {
                  "summary": "The stage stays nacosti_review; the application now waits on KEMRI's ISERC. The note goes only to KEMRI and NACOSTI. (NACOSTI)",
                  "value": {
                    "event_id": "devd4fcad-n2",
                    "requested_from": "source_iserc",
                    "note": "Please confirm whether the revised protocol covers the additional site in Siaya.",
                    "response_due_at": "2026-12-09"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same event_id again (duplicate).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {}
              }
            }
          },
          "201": {
            "description": "Opened: the request_id, the stage, on whom it now waits.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "request_to_iserc": {
                    "summary": "The stage stays nacosti_review; the application now waits on KEMRI's ISERC. The note goes only to KEMRI and NACOSTI. (NACOSTI, captured)",
                    "value": {
                      "result": "accepted",
                      "request_id": "58a2c3da-b2aa-4bc4-8108-f3cee904b6d8",
                      "stage": "nacosti_review",
                      "waiting_on": "source_iserc",
                      "requested_from": "source_iserc"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "not_owner: only the stage's holder asks.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                },
                "examples": {
                  "request_not_owner": {
                    "summary": "Only the stage's holder asks. (KEMRI, captured)",
                    "value": {
                      "result": "not_owner",
                      "stage": "nacosti_review",
                      "why": "only the holder of the nacosti review stage (NACOSTI) asks"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not yours to see.",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {}
              }
            }
          },
          "422": {
            "description": "rejected: no event_id or note, a recipient the caller may not ask, or a bad date or audience.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rejected"
                },
                "examples": {
                  "request_rejected": {
                    "summary": "A request needs its note. (NACOSTI, captured)",
                    "value": {
                      "result": "rejected",
                      "fields": [
                        "note"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Requests and documents"
        ],
        "operationId": "listRequests",
        "summary": "The requests on an application",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          }
        ],
        "description": "NACOSTI and the source ISERC see every request; PPB only its own.",
        "responses": {
          "200": {
            "description": "On whom it waits, and each request with its note and its answer.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RequestsList"
                },
                "examples": {
                  "requests_list": {
                    "summary": "The source ISERC sees every request on its application. (KEMRI, captured)",
                    "value": {
                      "application_id": "KE-KEMRI-2026-000046-6",
                      "waiting_on": "source_iserc",
                      "requests": [
                        {
                          "request_id": "58a2c3da-b2aa-4bc4-8108-f3cee904b6d8",
                          "requested_by": "NACOSTI",
                          "requested_from": "source_iserc",
                          "audience": "iserc_internal",
                          "note": "Please confirm whether the revised protocol covers the additional site in Siaya.",
                          "stage": "nacosti_review",
                          "state": "open",
                          "requested_at": "2026-12-02T12:21:44.477022+00:00",
                          "response_due_at": "2026-12-09"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not yours to see.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                }
              }
            }
          }
        }
      }
    },
    "/v2/applications/{application_id}/requests/{request_id}/responses": {
      "post": {
        "tags": [
          "Requests and documents"
        ],
        "operationId": "answerRequest",
        "summary": "Answer a request by its ID",
        "parameters": [
          {
            "name": "application_id",
            "in": "path",
            "required": true,
            "description": "The Application ID, KE-{ISERC}-{year}-{six digits}-{Luhn check digit}.",
            "schema": {
              "type": "string",
              "pattern": "^KE-[A-Z]{2,12}-\\d{4}-\\d{6}-\\d$"
            }
          },
          {
            "name": "request_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "The source ISERC answers, with a note and, if needed, a new document version. The requester may record an applicant's answer it received itself. information.responded goes to the source ISERC and the requester.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResponseIn"
              },
              "examples": {
                "response_with_document": {
                  "summary": "Answered by request ID, with a new document version; waiting_on goes back to the reviewer. (KEMRI)",
                  "value": {
                    "event_id": "devd4fcad-r4",
                    "note": "Yes: Siaya is covered; the site confirmation letter is attached.",
                    "document": {
                      "kind": "other",
                      "filename": "site-confirmation.pdf",
                      "sha256": "e25fef143c209fec8b7f57481f285f0d6e7369a04d5b732015893dfc3908d789",
                      "bytes": 861,
                      "source_url": "http://partners:8032/files/KEMRI/devd4fcad/site-confirmation.pdf"
                    }
                  }
                },
                "response_for_applicant": {
                  "summary": "The requester records the answer it received from the applicant itself. (NACOSTI)",
                  "value": {
                    "event_id": "devd4fcad-n6",
                    "note": "Receipt received on eCitizen."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The same event_id again (duplicate).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {}
              }
            }
          },
          "201": {
            "description": "Answered: the request is responded; waiting_on goes back to the reviewer unless another request is open; the document version if one was sent.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                },
                "examples": {
                  "response_with_document": {
                    "summary": "Answered by request ID, with a new document version; waiting_on goes back to the reviewer. (KEMRI, captured)",
                    "value": {
                      "result": "accepted",
                      "request_id": "58a2c3da-b2aa-4bc4-8108-f3cee904b6d8",
                      "state": "responded",
                      "waiting_on": "reviewer",
                      "document": {
                        "document_id": "0875e1f4-8c05-493f-9380-d1ae94b71ce1",
                        "kind": "other",
                        "version": 1,
                        "counts": true
                      }
                    }
                  },
                  "response_for_applicant": {
                    "summary": "The requester records the answer it received from the applicant itself. (NACOSTI, captured)",
                    "value": {
                      "result": "accepted",
                      "request_id": "f60a0914-0c9e-4360-a30d-e71f4bbf6c7b",
                      "state": "responded",
                      "waiting_on": "reviewer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "not_allowed: neither the source ISERC nor, for a request to the applicant, the requester.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refused"
                },
                "examples": {
                  "response_not_allowed": {
                    "summary": "A request to the ISERC is answered by the ISERC. (NACOSTI, captured)",
                    "value": {
                      "result": "not_allowed",
                      "why": "the source ISERC answers; the requester may record an applicant's answer it received"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown application or request, or not yours to see.",
            "headers": {},
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {}
              }
            }
          },
          "409": {
            "description": "not_open: the request was already answered or closed.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotOpen"
                },
                "examples": {
                  "response_not_open": {
                    "summary": "The request is already answered. (KEMRI, captured)",
                    "value": {
                      "result": "not_open",
                      "state": "responded"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "rejected (no event_id or note) or incomplete (the document doesn't fit).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Rejected"
                    },
                    {
                      "$ref": "#/components/schemas/Incomplete"
                    }
                  ]
                },
                "examples": {}
              }
            }
          }
        }
      }
    },
    "/v2/documents/{document_id}/content": {
      "get": {
        "tags": [
          "Requests and documents"
        ],
        "operationId": "openDocument",
        "summary": "Open a document version: the PDF itself",
        "parameters": [
          {
            "name": "document_id",
            "in": "path",
            "required": true,
            "description": "From a document version (GET /v2/applications/{id}) or an answer.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "For NACOSTI, PPB (a trial sent to it) and the source ISERC. TRACE checks the caller on every request, fetches the file server to server from the source system's source_url (signed: see the webhooks section, documentFetch), verifies its SHA-256 against the manifest, records the access and streams it. TRACE keeps no bytes. Demo: no malware scan (X-Trace-Scan: not-scanned-demo).",
        "responses": {
          "200": {
            "description": "The PDF.",
            "headers": {
              "X-Trace-Document": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Trace-Kind": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Trace-Version": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Trace-Sha256": {
                "schema": {
                  "type": "string"
                }
              },
              "X-Trace-Approved": {
                "schema": {
                  "enum": [
                    "true",
                    "false"
                  ]
                }
              },
              "X-Trace-Scan": {
                "schema": {
                  "const": "not-scanned-demo"
                }
              },
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/pdf"
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "not_found (unknown, or not yours: the same answer, nothing is revealed) or no_file (the source sent only the manifest).",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentError"
                },
                "examples": {
                  "document_content_denied": {
                    "summary": "Not entitled: the same answer as a document that does not exist. (MTRH, captured)",
                    "value": {
                      "result": "not_found"
                    }
                  },
                  "document_content_no_file": {
                    "summary": "The source sent only the manifest for this version. (NACOSTI, captured)",
                    "value": {
                      "result": "no_file",
                      "why": "the source sent only the manifest for this version; ask it for the file"
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "unavailable (the address is not on the source's registered host, or the source did not answer 200), checksum_mismatch (the file is not the version in the manifest) or too_large (over 20 MB). Nothing is passed on.",
            "headers": {
              "X-Correlation-ID": {
                "description": "One id per answer; quote it when reporting a problem. Sent on the POST /v2 calls.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentError"
                },
                "examples": {
                  "document_content_unavailable": {
                    "summary": "TRACE fetches only from the source organisation's registered host. (NACOSTI, captured)",
                    "value": {
                      "result": "unavailable",
                      "why": "the file's address is not on the source system's registered host"
                    }
                  },
                  "document_content_checksum_mismatch": {
                    "summary": "The file the source gave is not the version in the manifest: TRACE does not pass it on. (NACOSTI, captured)",
                    "value": {
                      "result": "checksum_mismatch",
                      "why": "the file the source gave is not the version in the manifest",
                      "expected_sha256": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
                      "received_sha256": "ac0a9cc34a83515851b0aee520c6199e74fa6c66e75fa9bf03056a79d28a7449"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/documents/{document_id}/access": {
      "get": {
        "tags": [
          "Requests and documents"
        ],
        "operationId": "documentAccess",
        "summary": "Who opened a document version",
        "parameters": [
          {
            "name": "document_id",
            "in": "path",
            "required": true,
            "description": "From a document version (GET /v2/applications/{id}) or an answer.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "For NACOSTI and the organisation that supplied the document.",
        "responses": {
          "200": {
            "description": "Every attempt with its result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccessLog"
                },
                "examples": {
                  "document_access": {
                    "summary": "Who opened this version, when, and with what result. (NACOSTI, captured)",
                    "value": {
                      "document_id": "4f52c58b-ce9b-4da0-88be-a4d34a051d45",
                      "kind": "protocol",
                      "version": 1,
                      "access": [
                        {
                          "by": "NACOSTI",
                          "result": "ok",
                          "at": "2026-12-02T12:21:54.056417+00:00",
                          "correlation_id": "9e460e0c30de48108d402fcab0987463"
                        },
                        {
                          "by": "MTRH",
                          "result": "denied",
                          "at": "2026-12-02T12:21:54.142030+00:00",
                          "correlation_id": "1f75d6fc4a3249419414f0ac83c7c975"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown, or not yours to see.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFound"
                },
                "examples": {
                  "document_access_denied": {
                    "summary": "Only NACOSTI and the organisation that supplied the document see its access log. (PPB, captured)",
                    "value": {
                      "result": "not_found"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v2/webhooks/deliveries": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listDeliveries",
        "summary": "The last 50 webhooks to this organisation",
        "responses": {
          "200": {
            "description": "Each delivery's state: pending, failed (retried every 30 seconds, at most 5 attempts) or delivered (a 2xx answer).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deliveries"
                },
                "examples": {
                  "deliveries": {
                    "summary": "The last 50 notices to this organisation. Shortened here to three. (NACOSTI, captured)",
                    "value": {
                      "deliveries": [
                        {
                          "delivery_id": "c603ef5e-fb29-46b5-b08c-db9f2ca091cb",
                          "event": "information.responded",
                          "application_id": "KE-KEMRI-2026-000045-8",
                          "state": "delivered",
                          "attempts": 1,
                          "last_status": 200,
                          "at": "2026-12-02T12:22:00.398747+00:00",
                          "delivered_at": "2026-12-02T12:22:03.318598+00:00"
                        },
                        {
                          "delivery_id": "fe43a2b5-9078-409d-bb2c-3f84451fbdfe",
                          "event": "document.version_added",
                          "application_id": "KE-KEMRI-2026-000045-8",
                          "state": "delivered",
                          "attempts": 1,
                          "last_status": 200,
                          "at": "2026-12-02T12:22:00.346196+00:00",
                          "delivered_at": "2026-12-02T12:22:03.318524+00:00"
                        },
                        {
                          "delivery_id": "449faee5-b6d3-4525-ac15-71a77f9b2f5a",
                          "event": "document.version_added",
                          "application_id": "KE-KEMRI-2026-000046-6",
                          "state": "delivered",
                          "attempts": 1,
                          "last_status": 200,
                          "at": "2026-12-02T12:21:57.556276+00:00",
                          "delivered_at": "2026-12-02T12:21:59.866850+00:00"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "No token, or an expired or unknown one: {\"error\": \"invalid_token\"}.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthError"
                },
                "examples": {
                  "no_token": {
                    "summary": "no_token (anyone, captured)",
                    "value": {
                      "error": "invalid_token"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "traceEvent": {
      "post": {
        "summary": "TRACE's notice to your registered url",
        "description": "Verify X-Trace-Signature (sha256= HMAC-SHA256 of the raw body with your secret, compared in constant time), then answer 2xx. Anything else is a failure: retried every 30 seconds, at most 5 attempts.",
        "parameters": [
          {
            "name": "X-Trace-Event",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Trace-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Trace-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookBody"
              },
              "examples": {
                "webhook_application_created": {
                  "summary": "application.created to NACOSTI (captured)",
                  "value": {
                    "delivery_id": "22919fbc-ee06-4a71-be6b-c0e8f38d5cbf",
                    "event": "application.created",
                    "application_id": "KE-MTRH-2026-000061-5",
                    "occurred_at": "2026-12-02T12:20:57.892605+00:00",
                    "data": {
                      "application_id": "KE-MTRH-2026-000061-5",
                      "source": "MTRH",
                      "source_ref": "MTRH/IREC/2026/DEVD4FCAD",
                      "route": "clinical_trial",
                      "stage": "ethics_review",
                      "study": {
                        "title": "Phase III trial of a single-dose sickle cell gene therapy in adolescents",
                        "type": "clinical_trial",
                        "sites": [
                          "Eldoret",
                          "Kakamega"
                        ],
                        "starts_on": "2027-03-01",
                        "ends_on": "2029-02-28"
                      },
                      "investigator": {
                        "name": "Prof. Kiprono Chelimo",
                        "institution": "Moi University"
                      },
                      "documents": [
                        {
                          "kind": "affiliation_letter",
                          "version": 1,
                          "document_id": "e4b87d16-db67-422b-8264-3ed09d8e1048",
                          "sha256": "41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24",
                          "file": "manifest_only"
                        },
                        {
                          "kind": "informed_consent_form",
                          "version": 1,
                          "document_id": "362bc6dc-dcf9-4568-bb16-6d2edccc36e3",
                          "sha256": "a04aa0a557c054c2e72c5a1657e0212ecd46c8d6fe21dca9ab6e1a687e5653a1",
                          "file": "manifest_only"
                        },
                        {
                          "kind": "investigators_brochure",
                          "version": 1,
                          "document_id": "f41c5686-4760-46d3-9a03-5ac31433c987",
                          "sha256": "a6d0ab662a3720d139371550dc9b97322169744bc14e13c0caab392c4c3b45b9",
                          "file": "manifest_only"
                        },
                        {
                          "kind": "protocol",
                          "version": 1,
                          "document_id": "05602b20-2241-4bf0-8d62-ef7847c2a522",
                          "sha256": "78f43bd46120077afc2348e0f3bb11f0136ae80a711ce46cb2593a51696e67cc",
                          "file": "manifest_only"
                        }
                      ],
                      "decisions": {}
                    }
                  }
                },
                "webhook_authorisation_expiring": {
                  "summary": "authorisation.expiring to NACOSTI (captured)",
                  "value": {
                    "delivery_id": "cefc32f3-5ed1-414f-bd8c-42a5f4f4f2b8",
                    "event": "authorisation.expiring",
                    "application_id": "KE-MTRH-2026-000060-7",
                    "occurred_at": "2026-12-02T12:20:36.857557+00:00",
                    "data": {
                      "application_id": "KE-MTRH-2026-000060-7",
                      "ppb_reference": "PPB/CTA/2026/1123",
                      "valid_until": "2026-12-27",
                      "days_left": 25
                    }
                  }
                },
                "webhook_licence_decided": {
                  "summary": "licence.decided to PPB (captured)",
                  "value": {
                    "delivery_id": "2d113e82-4a24-4baf-88f0-93acde832f5a",
                    "event": "licence.decided",
                    "application_id": "KE-MTRH-2026-000060-7",
                    "occurred_at": "2026-12-02T12:21:15.175232+00:00",
                    "data": {
                      "application_id": "KE-MTRH-2026-000060-7",
                      "outcome": "issued",
                      "reference": "NACOSTI/P/27/41377"
                    }
                  }
                },
                "webhook_information_requested": {
                  "summary": "information.requested to NACOSTI (captured)",
                  "value": {
                    "delivery_id": "0c2cd40c-1773-4d69-9246-d070321bb500",
                    "event": "information.requested",
                    "application_id": "KE-KEMRI-2026-000046-6",
                    "occurred_at": "2026-12-02T12:21:49.261234+00:00",
                    "data": {
                      "request_id": "f60a0914-0c9e-4360-a30d-e71f4bbf6c7b",
                      "requested_by": "NACOSTI",
                      "requested_from": "applicant",
                      "audience": "applicant",
                      "note": "Please upload the licence fee receipt.",
                      "stage": "nacosti_review",
                      "state": "open",
                      "requested_at": "2026-12-02T12:21:49.232132+00:00",
                      "response_due_at": null,
                      "application_id": "KE-KEMRI-2026-000046-6",
                      "waiting_on": "applicant"
                    }
                  }
                },
                "webhook_information_responded": {
                  "summary": "information.responded to NACOSTI (captured)",
                  "value": {
                    "delivery_id": "c603ef5e-fb29-46b5-b08c-db9f2ca091cb",
                    "event": "information.responded",
                    "application_id": "KE-KEMRI-2026-000045-8",
                    "occurred_at": "2026-12-02T12:22:00.398727+00:00",
                    "data": {
                      "request_id": "608ba3ca-56fb-4de1-abda-54a419c7deec",
                      "requested_by": "NACOSTI",
                      "requested_from": "source_iserc",
                      "audience": "iserc_internal",
                      "note": "Please confirm whether the revised protocol covers the additional site in Siaya.",
                      "stage": "nacosti_review",
                      "state": "responded",
                      "requested_at": "2026-12-02T12:21:42.849052+00:00",
                      "response_due_at": null,
                      "response": {
                        "note": "Yes: Siaya is covered; the site confirmation letter is attached.",
                        "responded_by": "KEMRI",
                        "responded_at": "2026-12-02T12:22:00.355546+00:00",
                        "document_id": "d1d6d1f4-2c18-4d03-9b17-5f45ff3136ca"
                      },
                      "application_id": "KE-KEMRI-2026-000045-8",
                      "waiting_on": "reviewer"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received. Any 2xx acknowledges."
          }
        }
      }
    },
    "documentFetch": {
      "get": {
        "summary": "TRACE fetches a file from your source_url",
        "description": "Only when an entitled reader opens the document. Serve the file only when X-Trace-Signature equals sha256= HMAC-SHA256 of \"GET {path}\\n{timestamp}\" with your TRACE webhook secret ({path} is the source_url's path and query; {timestamp} is X-Trace-Timestamp), compared in constant time, and the timestamp is recent (how recent is your choice: the demo partners accept 5 minutes). TRACE fetches only from the host of your registered webhook receiver, waits 10 seconds, takes at most 20 MB, and checks the bytes against the manifest's sha256.",
        "parameters": [
          {
            "name": "X-Trace-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-Trace-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            }
          },
          {
            "name": "X-Trace-Document",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Trace-Requester",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Who is opening it: NACOSTI, PPB or your own code."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The PDF, exactly the bytes in the manifest.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/pdf"
                }
              }
            }
          },
          "401": {
            "description": "Not TRACE, or an old request: refuse it. TRACE answers its caller 502 unavailable."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AuthError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_token",
              "invalid_client",
              "unsupported_grant_type"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "Token": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string"
          },
          "token_type": {
            "const": "Bearer"
          },
          "expires_in": {
            "type": "integer",
            "description": "Seconds: 900 (15 minutes)."
          }
        },
        "required": [
          "access_token",
          "token_type",
          "expires_in"
        ]
      },
      "Study": {
        "type": "object",
        "required": [
          "title",
          "type",
          "sites",
          "starts_on",
          "ends_on"
        ],
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 300
          },
          "type": {
            "enum": [
              "non_clinical",
              "clinical_trial"
            ]
          },
          "sites": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 80
            },
            "minItems": 1,
            "maxItems": 20
          },
          "starts_on": {
            "type": "string",
            "format": "date"
          },
          "ends_on": {
            "type": "string",
            "format": "date"
          }
        },
        "description": "Only these fields are kept; anything else is dropped."
      },
      "Investigator": {
        "type": "object",
        "required": [
          "name",
          "institution"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "institution": {
            "type": "string",
            "maxLength": 160
          }
        },
        "description": "Only name and institution are kept: an ID number, phone or date of birth sent here is dropped, never stored."
      },
      "Document": {
        "type": "object",
        "required": [
          "kind",
          "filename",
          "sha256",
          "bytes"
        ],
        "properties": {
          "kind": {
            "enum": [
              "protocol",
              "affiliation_letter",
              "informed_consent_form",
              "investigators_brochure",
              "other",
              "ppb_application_form",
              "insurance_certificate",
              "ppb_authorisation_letter"
            ]
          },
          "filename": {
            "type": "string",
            "pattern": "(?i)\\.pdf$",
            "description": "A PDF."
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "bytes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20971520
          },
          "template": {
            "type": "string",
            "description": "Optional. If sent for a protocol or an affiliation letter it must be the current template: NACOSTI-PROTOCOL-2026, NACOSTI-AFFILIATION-2026."
          },
          "source_url": {
            "type": "string",
            "maxLength": 300,
            "description": "Optional. Where your own system serves this file to TRACE (http or https, on the same host as your registered webhook receiver). Without it the version is manifest_only and cannot be opened through TRACE."
          }
        }
      },
      "Submission": {
        "type": "object",
        "required": [
          "event_id",
          "source_ref",
          "study",
          "investigator",
          "documents"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "maxLength": 120,
            "description": "Your unique id for this call; the same id again gets the first answer back."
          },
          "source_ref": {
            "type": "string",
            "maxLength": 120,
            "description": "Your own reference; one application per source_ref."
          },
          "study": {
            "$ref": "#/components/schemas/Study"
          },
          "investigator": {
            "$ref": "#/components/schemas/Investigator"
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Document"
            },
            "description": "Required kinds by route: non_clinical protocol and affiliation_letter; clinical_trial also informed_consent_form and investigators_brochure."
          }
        }
      },
      "DocumentVersion": {
        "allOf": [
          {
            "type": "object",
            "required": [
              "event_id"
            ],
            "properties": {
              "event_id": {
                "type": "string",
                "maxLength": 120
              }
            }
          },
          {
            "$ref": "#/components/schemas/Document"
          }
        ]
      },
      "Event": {
        "type": "object",
        "required": [
          "event_id",
          "type"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "maxLength": 120
          },
          "type": {
            "enum": [
              "ethics.changes_requested",
              "ethics.approved",
              "ethics.rejected",
              "ppb.changes_requested",
              "ppb.authorised",
              "ppb.rejected",
              "licence.changes_requested",
              "licence.issued",
              "licence.rejected"
            ]
          },
          "reference": {
            "type": "string",
            "maxLength": 80,
            "description": "Your decision's reference."
          },
          "decided_on": {
            "type": "string",
            "format": "date",
            "description": "Kept in your event; informational."
          },
          "valid_until": {
            "type": "string",
            "format": "date",
            "description": "Required for ppb.authorised."
          },
          "note": {
            "type": "string",
            "maxLength": 2000,
            "description": "Required for a *.changes_requested event: the request's note."
          },
          "requested_from": {
            "enum": [
              "source_iserc",
              "applicant"
            ],
            "description": "For a *.changes_requested event. The ISERC asks only the applicant."
          },
          "audience": {
            "enum": [
              "iserc_internal",
              "applicant"
            ]
          },
          "response_due_at": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "RequestIn": {
        "type": "object",
        "required": [
          "event_id",
          "note"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "maxLength": 120
          },
          "requested_from": {
            "enum": [
              "source_iserc",
              "applicant"
            ],
            "description": "Default: applicant when the ISERC asks, source_iserc when PPB or NACOSTI asks. The ISERC cannot ask itself."
          },
          "note": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "description": "The actual note: what is asked."
          },
          "audience": {
            "enum": [
              "iserc_internal",
              "applicant"
            ],
            "description": "Who may read the note. Default: iserc_internal for source_iserc, applicant for applicant."
          },
          "response_due_at": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "ResponseIn": {
        "type": "object",
        "required": [
          "event_id",
          "note"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "maxLength": 120
          },
          "note": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          },
          "document": {
            "$ref": "#/components/schemas/Document"
          }
        }
      },
      "RequestItem": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "requested_by": {
            "type": "string"
          },
          "requested_from": {
            "enum": [
              "source_iserc",
              "applicant"
            ]
          },
          "audience": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "stage": {
            "type": "string"
          },
          "state": {
            "enum": [
              "open",
              "responded",
              "closed"
            ],
            "description": "closed: the stage moved on while it was open."
          },
          "requested_at": {
            "type": "string"
          },
          "response_due_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "response": {
            "type": "object",
            "properties": {
              "note": {
                "type": "string"
              },
              "responded_by": {
                "type": "string"
              },
              "responded_at": {
                "type": "string"
              },
              "document_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "RequestsList": {
        "type": "object",
        "properties": {
          "application_id": {
            "type": "string"
          },
          "waiting_on": {
            "enum": [
              "reviewer",
              "source_iserc",
              "applicant"
            ]
          },
          "requests": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RequestItem"
            }
          }
        }
      },
      "NotOpen": {
        "type": "object",
        "properties": {
          "result": {
            "const": "not_open"
          },
          "state": {
            "type": "string"
          }
        }
      },
      "DocumentError": {
        "type": "object",
        "properties": {
          "result": {
            "enum": [
              "not_found",
              "no_file",
              "unavailable",
              "checksum_mismatch",
              "too_large"
            ]
          },
          "why": {
            "type": "string"
          },
          "expected_sha256": {
            "type": "string"
          },
          "received_sha256": {
            "type": "string"
          }
        }
      },
      "AccessLog": {
        "type": "object",
        "properties": {
          "document_id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "access": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "by": {
                  "type": "string"
                },
                "result": {
                  "enum": [
                    "ok",
                    "denied",
                    "no_file",
                    "unavailable",
                    "checksum_mismatch",
                    "too_large"
                  ]
                },
                "at": {
                  "type": "string"
                },
                "correlation_id": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Accepted": {
        "type": "object",
        "properties": {
          "result": {
            "enum": [
              "accepted",
              "duplicate"
            ]
          },
          "application_id": {
            "type": "string"
          },
          "route": {
            "enum": [
              "non_clinical",
              "clinical_trial"
            ]
          },
          "stage": {
            "type": "string"
          },
          "routed_to": {
            "enum": [
              "PPB",
              "NACOSTI"
            ]
          },
          "waiting_on": {
            "enum": [
              "reviewer",
              "source_iserc",
              "applicant"
            ]
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "requested_from": {
            "enum": [
              "source_iserc",
              "applicant"
            ]
          },
          "state": {
            "type": "string"
          },
          "document_id": {
            "type": "string"
          },
          "document": {
            "type": "object",
            "properties": {
              "document_id": {
                "type": "string"
              },
              "kind": {
                "type": "string"
              },
              "version": {
                "type": "integer"
              },
              "counts": {
                "type": "boolean"
              },
              "why": {
                "type": "string"
              }
            }
          },
          "kind": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "counts": {
            "type": "boolean"
          },
          "why": {
            "type": "string"
          }
        },
        "required": [
          "result"
        ]
      },
      "Incomplete": {
        "type": "object",
        "required": [
          "result",
          "missing",
          "wrong"
        ],
        "properties": {
          "result": {
            "const": "incomplete"
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "wrong": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string"
                },
                "filename": {
                  "type": "string"
                },
                "why": {
                  "type": "string"
                }
              }
            }
          },
          "message": {
            "type": "string"
          }
        }
      },
      "Rejected": {
        "type": "object",
        "required": [
          "result",
          "fields"
        ],
        "properties": {
          "result": {
            "const": "rejected"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "why": {
            "type": "string"
          }
        }
      },
      "Refused": {
        "type": "object",
        "required": [
          "result"
        ],
        "properties": {
          "result": {
            "enum": [
              "not_owner",
              "not_allowed"
            ]
          },
          "stage": {
            "type": "string"
          },
          "why": {
            "type": "string"
          }
        }
      },
      "NotFound": {
        "type": "object",
        "properties": {
          "result": {
            "const": "not_found"
          }
        }
      },
      "Application": {
        "type": "object",
        "description": "NACOSTI sees every application with its history; an ISERC its own (with history); PPB the trials sent to it (no history). Each document version carries document_id and file (at_source or manifest_only); each timeline entry waiting_days and reviewer_days; requests lists the requests the caller may see.",
        "properties": {
          "application_id": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "source_ref": {
            "type": "string"
          },
          "route": {
            "type": "string"
          },
          "stage": {
            "type": "string"
          },
          "study": {
            "$ref": "#/components/schemas/Study"
          },
          "investigator": {
            "$ref": "#/components/schemas/Investigator"
          },
          "documents": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "decisions": {
            "type": "object"
          },
          "ppb_valid_until": {
            "type": "string",
            "format": "date"
          },
          "waiting_on": {
            "type": "string"
          },
          "holder": {
            "type": "string"
          },
          "days_in_stage": {
            "type": "number"
          },
          "flag": {
            "enum": [
              "on_time",
              "amber",
              "red",
              "done"
            ]
          },
          "expiring": {
            "type": "boolean"
          },
          "timeline": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "requests": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RequestItem"
            }
          }
        }
      },
      "Pipeline": {
        "type": "object",
        "properties": {
          "thresholds": {
            "type": "object"
          },
          "counts": {
            "type": "object"
          },
          "red": {
            "type": "integer"
          },
          "amber": {
            "type": "integer"
          },
          "expiring": {
            "type": "integer"
          },
          "applications": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "Subscription": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "http:// or https://"
          },
          "events": {
            "type": "array",
            "items": {
              "enum": [
                "application.created",
                "document.version_added",
                "stage.changed",
                "package.sent_to_ppb",
                "package.sent_to_nacosti",
                "authorisation.expiring",
                "stage.overdue",
                "licence.decided",
                "information.requested",
                "information.responded"
              ]
            },
            "description": "Leave out for every event."
          }
        }
      },
      "SubscriptionAnswer": {
        "type": "object",
        "properties": {
          "result": {
            "const": "accepted"
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "secret": {
            "type": "string",
            "description": "whsec_…, returned once. Registering again replaces the subscription and its secret."
          }
        }
      },
      "Deliveries": {
        "type": "object",
        "properties": {
          "deliveries": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "delivery_id": {
                  "type": "string"
                },
                "event": {
                  "type": "string"
                },
                "application_id": {
                  "type": "string"
                },
                "state": {
                  "enum": [
                    "pending",
                    "failed",
                    "delivered"
                  ]
                },
                "attempts": {
                  "type": "integer"
                },
                "last_status": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "at": {
                  "type": "string"
                },
                "delivered_at": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "WebhookBody": {
        "type": "object",
        "required": [
          "delivery_id",
          "event",
          "application_id",
          "occurred_at",
          "data"
        ],
        "properties": {
          "delivery_id": {
            "type": "string"
          },
          "event": {
            "enum": [
              "application.created",
              "document.version_added",
              "stage.changed",
              "package.sent_to_ppb",
              "package.sent_to_nacosti",
              "authorisation.expiring",
              "stage.overdue",
              "licence.decided",
              "information.requested",
              "information.responded"
            ]
          },
          "application_id": {
            "type": "string"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object"
          }
        }
      }
    },
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "From POST /v1/token; 900 seconds."
      },
      "clientCredentials": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://trace-api.apprenticecloud.com/v1/token",
            "scopes": {}
          }
        }
      }
    }
  }
}