{
  "info": {
    "name": "TRACE /v2 (demonstration)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "The journey in order. Each organisation has its own key: put the ISERC's client_id and client_secret in for folders 1 and 2, PPB's for 3, NACOSTI's for 4 (the token is fetched again when the client id changes). Keys are handed over privately."
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://trace-api.apprenticecloud.com"
    },
    {
      "key": "client_id",
      "value": ""
    },
    {
      "key": "client_secret",
      "value": ""
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "token_for",
      "value": ""
    },
    {
      "key": "token_expires",
      "value": "0"
    },
    {
      "key": "application_id",
      "value": ""
    },
    {
      "key": "request_id",
      "value": ""
    },
    {
      "key": "document_id",
      "value": ""
    }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{token}}",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// fetch a token when there is none, it is about to expire, or the client id changed",
          "if (pm.request.url.getPath() === '/v1/token') { return; }",
          "const id = pm.collectionVariables.get('client_id'), secret = pm.collectionVariables.get('client_secret');",
          "const fresh = pm.collectionVariables.get('token') && pm.collectionVariables.get('token_for') === id && Date.now() < Number(pm.collectionVariables.get('token_expires'));",
          "if (!fresh) {",
          "  pm.sendRequest({ url: pm.collectionVariables.get('base_url') + '/v1/token', method: 'POST', header: { 'Content-Type': 'application/x-www-form-urlencoded' },",
          "    body: { mode: 'urlencoded', urlencoded: [{ key: 'grant_type', value: 'client_credentials' }, { key: 'client_id', value: id }, { key: 'client_secret', value: secret }] } }, (err, res) => {",
          "    if (err || res.code !== 200) { console.error('TRACE token failed', err || res.code); return; }",
          "    const j = res.json(); pm.collectionVariables.set('token', j.access_token); pm.collectionVariables.set('token_for', id);",
          "    pm.collectionVariables.set('token_expires', String(Date.now() + (j.expires_in - 30) * 1000));",
          "  });",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "0 · Get a token",
      "description": "Optional: the collection fetches one by itself before each call.",
      "item": [
        {
          "name": "Token (client credentials)",
          "request": {
            "method": "POST",
            "auth": {
              "type": "noauth"
            },
            "header": [
              {
                "key": "Content-Type",
                "value": "application/x-www-form-urlencoded"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v1/token",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "token"
              ]
            },
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "client_credentials"
                },
                {
                  "key": "client_id",
                  "value": "{{client_id}}"
                },
                {
                  "key": "client_secret",
                  "value": "{{client_secret}}"
                }
              ]
            },
            "description": "Answer: {access_token, token_type: Bearer, expires_in: 900}."
          }
        }
      ]
    },
    {
      "name": "1 · Submit (the ISERC's key)",
      "description": "Submit; the accepted one stores application_id for the next folders.",
      "item": [
        {
          "name": "Submit without a required document (422 incomplete)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"source_ref\": \"KEMRI/SERU/2026/{{$timestamp}}\",\n  \"study\": {\n    \"title\": \"Malaria vaccine uptake among children under five in Kisumu County\",\n    \"type\": \"non_clinical\",\n    \"sites\": [\n      \"Kisumu\"\n    ],\n    \"starts_on\": \"2027-01-15\",\n    \"ends_on\": \"2027-12-15\"\n  },\n  \"investigator\": {\n    \"name\": \"Dr. Achieng Otieno\",\n    \"institution\": \"Maseno University\"\n  },\n  \"documents\": [\n    {\n      \"kind\": \"protocol\",\n      \"filename\": \"protocol.pdf\",\n      \"sha256\": \"646d0571e44e0f99d8cb46246fe7a7fa5057b05e0cdf82203576b335c8c6b935\",\n      \"bytes\": 192156\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "Nothing is created. Captured answer: 422 {\"result\":\"incomplete\",\"missing\":[\"affiliation_letter\"],\"wrong\":[],\"message\":\"Nothing was created or sent on. Send the application again with every document.\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 422\", () => pm.response.to.have.status(422));"
                ]
              }
            }
          ]
        },
        {
          "name": "Submit with an unfit document (422 incomplete, wrong)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"source_ref\": \"KEMRI/SERU/2026/{{$timestamp}}\",\n  \"study\": {\n    \"title\": \"Malaria vaccine uptake among children under five in Kisumu County\",\n    \"type\": \"non_clinical\",\n    \"sites\": [\n      \"Kisumu\"\n    ],\n    \"starts_on\": \"2027-01-15\",\n    \"ends_on\": \"2027-12-15\"\n  },\n  \"investigator\": {\n    \"name\": \"Dr. Achieng Otieno\",\n    \"institution\": \"Maseno University\"\n  },\n  \"documents\": [\n    {\n      \"kind\": \"protocol\",\n      \"filename\": \"protocol.docx\",\n      \"sha256\": \"3fd6c76d2d23bbb8ae942ca93d8a0ac0fffdb726518396dd15f11615374b49ab\",\n      \"bytes\": 193169\n    },\n    {\n      \"kind\": \"affiliation_letter\",\n      \"filename\": \"affiliation-letter.pdf\",\n      \"sha256\": \"41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24\",\n      \"bytes\": 202286,\n      \"template\": \"NACOSTI-AFFILIATION-2024\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "A Word file and an out-of-date template. Captured answer: 422 {\"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 o"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 422\", () => pm.response.to.have.status(422));"
                ]
              }
            }
          ]
        },
        {
          "name": "Submit with bad fields (422 rejected)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"source_ref\": \"KEMRI/SERU/2026/{{$timestamp}}\",\n  \"study\": {\n    \"title\": \"\",\n    \"type\": \"non_clinical\",\n    \"sites\": [\n      \"Kisumu\"\n    ],\n    \"starts_on\": \"15/01/2027\",\n    \"ends_on\": \"2027-12-15\"\n  },\n  \"investigator\": {\n    \"name\": \"Dr. Achieng Otieno\"\n  },\n  \"documents\": [\n    {\n      \"kind\": \"protocol\",\n      \"filename\": \"protocol.pdf\",\n      \"sha256\": \"646d0571e44e0f99d8cb46246fe7a7fa5057b05e0cdf82203576b335c8c6b935\",\n      \"bytes\": 192156\n    },\n    {\n      \"kind\": \"affiliation_letter\",\n      \"filename\": \"affiliation-letter.pdf\",\n      \"sha256\": \"41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24\",\n      \"bytes\": 202286\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 422 {\"result\":\"rejected\",\"fields\":[\"study.title\",\"study.starts_on\",\"investigator.institution\"]}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 422\", () => pm.response.to.have.status(422));"
                ]
              }
            }
          ]
        },
        {
          "name": "Submit a clinical trial (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"source_ref\": \"MTRH/IREC/2026/{{$timestamp}}\",\n  \"study\": {\n    \"title\": \"Phase III trial of a single-dose sickle cell gene therapy in adolescents\",\n    \"type\": \"clinical_trial\",\n    \"sites\": [\n      \"Eldoret\",\n      \"Kakamega\"\n    ],\n    \"starts_on\": \"2027-03-01\",\n    \"ends_on\": \"2029-02-28\"\n  },\n  \"investigator\": {\n    \"name\": \"Prof. Kiprono Chelimo\",\n    \"institution\": \"Moi University\"\n  },\n  \"documents\": [\n    {\n      \"kind\": \"protocol\",\n      \"filename\": \"protocol-v1.pdf\",\n      \"sha256\": \"78f43bd46120077afc2348e0f3bb11f0136ae80a711ce46cb2593a51696e67cc\",\n      \"bytes\": 195195\n    },\n    {\n      \"kind\": \"affiliation_letter\",\n      \"filename\": \"affiliation-letter.pdf\",\n      \"sha256\": \"41eba867c9f8691f343bd033a54a3eabe4683d83ff70730a2942e4fcebf23c24\",\n      \"bytes\": 202286\n    },\n    {\n      \"kind\": \"informed_consent_form\",\n      \"filename\": \"consent-form.pdf\",\n      \"sha256\": \"a04aa0a557c054c2e72c5a1657e0212ecd46c8d6fe21dca9ab6e1a687e5653a1\",\n      \"bytes\": 196208\n    },\n    {\n      \"kind\": \"investigators_brochure\",\n      \"filename\": \"brochure.pdf\",\n      \"sha256\": \"a6d0ab662a3720d139371550dc9b97322169744bc14e13c0caab392c4c3b45b9\",\n      \"bytes\": 192156\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "Four documents. Captured answer: 201 {\"result\":\"accepted\",\"application_id\":\"KE-MTRH-2026-000061-5\",\"route\":\"clinical_trial\",\"stage\":\"ethics_review\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 201 && pm.response.json().application_id) { pm.collectionVariables.set(\"application_id\", pm.response.json().application_id); }",
                  "pm.test(\"answered\", () => pm.expect(pm.response.code).to.be.below(500));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "2 · Ethics review (the ISERC's key)",
      "description": "",
      "item": [
        {
          "name": "Ask for changes (200)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/events",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "events"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"type\": \"ethics.changes_requested\",\n  \"reference\": \"MTRH/IREC/CR/1\",\n  \"note\": \"Revise the dosing section.\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 200 {\"result\":\"accepted\",\"request_id\":\"4a7646b6-9f31-448c-92dc-5c663d8c4343\",\"stage\":\"ethics_review\",\"waiting_on\":\"applicant\",\"requested_from\":\"applicant\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "New protocol version (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/documents",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "documents"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"kind\": \"protocol\",\n  \"filename\": \"protocol-v2.pdf\",\n  \"sha256\": \"194077f5647a40a8a6d13dfa48c746182d08a3645726a634254b06faf07d624c\",\n  \"bytes\": 195195\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"result\":\"accepted\",\"document_id\":\"7372e628-a6f5-42d1-b6c9-03a88193c316\",\"kind\":\"protocol\",\"version\":2,\"counts\":true}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        },
        {
          "name": "Approve (200, routed to PPB)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/events",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "events"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"type\": \"ethics.approved\",\n  \"reference\": \"MTRH/IREC/2026/0412\",\n  \"decided_on\": \"2026-12-02\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 200 {\"result\":\"accepted\",\"stage\":\"ppb_review\",\"routed_to\":\"PPB\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "A late version after approval (201, counts false)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/documents",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "documents"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"kind\": \"protocol\",\n  \"filename\": \"protocol-v3.pdf\",\n  \"sha256\": \"d040e5127c87262a53ba613154ba2a84e259b70b2878f1956fd17b72aad15ba6\",\n  \"bytes\": 195195\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"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\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "3 · PPB (PPB's key)",
      "description": "Clinical trials only.",
      "item": [
        {
          "name": "Add a PPB document (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/documents",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "documents"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"kind\": \"ppb_application_form\",\n  \"filename\": \"ppb-application-form.pdf\",\n  \"sha256\": \"9e93244427056e452b66af561b0b6539be98581895cd38f644855fe764b0a5ef\",\n  \"bytes\": 204312\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"result\":\"accepted\",\"document_id\":\"0794103c-6545-4c9b-a5e1-36a10615aac0\",\"kind\":\"ppb_application_form\",\"version\":1,\"counts\":true}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        },
        {
          "name": "Authorise (200, routed to NACOSTI)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/events",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "events"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"type\": \"ppb.authorised\",\n  \"reference\": \"PPB/CT/2026/0103\",\n  \"decided_on\": \"2026-12-02\",\n  \"valid_until\": \"2026-12-27\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "valid_until is required. Captured answer: 200 {\"result\":\"accepted\",\"stage\":\"nacosti_review\",\"routed_to\":\"NACOSTI\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "4 · NACOSTI (NACOSTI's key)",
      "description": "",
      "item": [
        {
          "name": "Read the application (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}"
              ]
            },
            "description": " Captured answer: 200 {\"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\""
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "The pipeline (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/pipeline",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "pipeline"
              ]
            },
            "description": " Captured answer: 200 {\"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\":\""
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "Issue the licence (200)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/events",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "events"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"type\": \"licence.issued\",\n  \"reference\": \"NACOSTI/P/26/0412\",\n  \"decided_on\": \"2026-12-02\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 200 {\"result\":\"accepted\",\"stage\":\"licensed\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "Webhook deliveries (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/webhooks/deliveries",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "webhooks",
                "deliveries"
              ]
            },
            "description": " Captured answer: 200 {\"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\":"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "6 · A file at its source (the ISERC's key)",
      "description": "KEMRI's application whose manifest carries source_url: each file stays in KEMRI's own system.",
      "item": [
        {
          "name": "Submit with files at the source (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"source_ref\": \"KEMRI/SERU/2026/{{$timestamp}}\",\n  \"study\": {\n    \"title\": \"Malaria vaccine uptake among children under five in Kisumu County\",\n    \"type\": \"non_clinical\",\n    \"sites\": [\n      \"Kisumu\"\n    ],\n    \"starts_on\": \"2027-01-15\",\n    \"ends_on\": \"2027-12-15\"\n  },\n  \"investigator\": {\n    \"name\": \"Dr. Achieng Otieno\",\n    \"institution\": \"Maseno University\"\n  },\n  \"documents\": [\n    {\n      \"kind\": \"protocol\",\n      \"filename\": \"protocol.pdf\",\n      \"sha256\": \"a748f27f1e4b7e11c14e9df6c8a1f942930ca04775fa4e80eab4d5a616f5dcd3\",\n      \"bytes\": 847,\n      \"source_url\": \"http://partners:8032/files/KEMRI/devd4fcad/protocol.pdf\"\n    },\n    {\n      \"kind\": \"affiliation_letter\",\n      \"filename\": \"affiliation-letter.pdf\",\n      \"sha256\": \"95d2375ddc8d0b809260182b85b46598bbdc1775f89c50ae371127ce56e0eb3a\",\n      \"bytes\": 861,\n      \"source_url\": \"http://partners:8032/files/KEMRI/devd4fcad/affiliation-letter.pdf\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"result\":\"accepted\",\"application_id\":\"KE-KEMRI-2026-000046-6\",\"route\":\"non_clinical\",\"stage\":\"ethics_review\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 201) { pm.collectionVariables.set(\"application_id\", pm.response.json().application_id); }",
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        },
        {
          "name": "Ethics approves, to NACOSTI (200)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/events",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "events"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"type\": \"ethics.approved\",\n  \"reference\": \"KEMRI/ERC/2026/0412\",\n  \"decided_on\": \"2026-12-02\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 200 {\"result\":\"accepted\",\"stage\":\"nacosti_review\",\"routed_to\":\"NACOSTI\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "7 · NACOSTI asks the ISERC (NACOSTI's key)",
      "description": "The stage stays; the application waits on the source ISERC.",
      "item": [
        {
          "name": "Ask the source ISERC (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/requests",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "requests"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"requested_from\": \"source_iserc\",\n  \"note\": \"Please confirm whether the revised protocol covers the additional site in Siaya.\",\n  \"response_due_at\": \"2026-12-09\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"result\":\"accepted\",\"request_id\":\"58a2c3da-b2aa-4bc4-8108-f3cee904b6d8\",\"stage\":\"nacosti_review\",\"waiting_on\":\"source_iserc\",\"requested_from\":\"source_iserc\"}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 201) { pm.collectionVariables.set(\"request_id\", pm.response.json().request_id); }",
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "8 · The ISERC answers (the ISERC's key)",
      "description": "",
      "item": [
        {
          "name": "The requests on the application (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/requests",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "requests"
              ]
            },
            "description": " Captured answer: 200 {\"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 "
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "Answer by request ID, with a letter (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}/requests/{{request_id}}/responses",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}",
                "requests",
                "{{request_id}}",
                "responses"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{$guid}}\",\n  \"note\": \"Yes: Siaya is covered; the site confirmation letter is attached.\",\n  \"document\": {\n    \"kind\": \"other\",\n    \"filename\": \"site-confirmation.pdf\",\n    \"sha256\": \"e25fef143c209fec8b7f57481f285f0d6e7369a04d5b732015893dfc3908d789\",\n    \"bytes\": 861,\n    \"source_url\": \"http://partners:8032/files/KEMRI/devd4fcad/site-confirmation.pdf\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": " Captured answer: 201 {\"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}}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 201\", () => pm.response.to.have.status(201));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "9 · NACOSTI opens the protocol (NACOSTI's key)",
      "description": "TRACE fetches the PDF from KEMRI's system, checks it and records the opening.",
      "item": [
        {
          "name": "Read the application (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/applications/{{application_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "applications",
                "{{application_id}}"
              ]
            },
            "description": "Stores the protocol's document_id. Captured answer: 200 {\"application_id\":\"KE-KEMRI-2026-000046-6\",\"source\":\"KEMRI\",\"source_ref\":\"KEMRI/SERU/2026/DEVD4FCAD-R\",\"route\":\"non_clinical\",\"stage\":\"nacosti_review\",\"study\":{\"title\":\"Malaria vaccine uptake among children under five in Kisumu County\",\"type\":\"non_clinical\",\"sites\":[\"Kisumu\"],\"starts_on\":\"2027-01-15"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = (pm.response.json().documents || []).find((x) => x.kind === \"protocol\"); if (d) { pm.collectionVariables.set(\"document_id\", d.versions[0].document_id); }",
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        },
        {
          "name": "Open the protocol (200, the PDF)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/documents/{{document_id}}/content",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "documents",
                "{{document_id}}",
                "content"
              ]
            },
            "description": "The answer is the PDF, with X-Trace-Kind, X-Trace-Version, X-Trace-Sha256, X-Trace-Approved and X-Trace-Scan."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"a PDF\", () => pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"application/pdf\"));"
                ]
              }
            }
          ]
        },
        {
          "name": "Who opened it (200)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/v2/documents/{{document_id}}/access",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "documents",
                "{{document_id}}",
                "access"
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "5 · Webhooks (any key)",
      "description": "Registering returns the signing secret once and replaces any earlier subscription and secret.",
      "item": [
        {
          "name": "Register a webhook url (201)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/v2/webhooks",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v2",
                "webhooks"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"url\": \"https://your-system.example/trace/webhooks\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "Answer: {result, url, events, secret}. Keep the secret."
          }
        }
      ]
    }
  ]
}