{
  "info": {
    "name": "RSI Public Platform API (sandbox)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      { "key": "token", "value": "{{accessToken}}", "type": "string" }
    ]
  },
  "variable": [
    { "key": "baseUrl", "value": "https://sandbox.redspotinteractive.com" },
    { "key": "clientId", "value": "" },
    { "key": "clientSecret", "value": "" },
    { "key": "accessToken", "value": "" },
    { "key": "patientId", "value": "" },
    { "key": "slotId", "value": "" },
    { "key": "appointmentId", "value": "" },
    { "key": "confirmationToken", "value": "" }
  ],
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Get token",
          "request": {
            "method": "POST",
            "auth": { "type": "noauth" },
            "header": [
              { "key": "Content-Type", "value": "application/x-www-form-urlencoded" }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials", "type": "text" },
                { "key": "client_id", "value": "{{clientId}}", "type": "text" },
                { "key": "client_secret", "value": "{{clientSecret}}", "type": "text" },
                { "key": "scope", "value": "practices:read slots:read patients:read appointments:read patients:write appointments:book appointments:cancel appointments:confirm", "type": "text" }
              ]
            },
            "url": {
              "raw": "{{baseUrl}}/oauth/connect/token",
              "host": ["{{baseUrl}}"],
              "path": ["oauth", "connect", "token"]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.collectionVariables.set('accessToken', pm.response.json().access_token);"
                ]
              }
            }
          ],
          "response": []
        }
      ]
    },
    {
      "name": "Directory",
      "item": [
        {
          "name": "Capabilities",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/capabilities",
              "host": ["{{baseUrl}}"],
              "path": ["api", "capabilities"]
            }
          },
          "response": []
        },
        {
          "name": "Locations",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/locations",
              "host": ["{{baseUrl}}"],
              "path": ["api", "locations"]
            }
          },
          "response": []
        },
        {
          "name": "Providers",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/providers?locationId=",
              "host": ["{{baseUrl}}"],
              "path": ["api", "providers"],
              "query": [
                { "key": "locationId", "value": "" }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Visit types",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/visit-types",
              "host": ["{{baseUrl}}"],
              "path": ["api", "visit-types"]
            }
          },
          "response": []
        },
        {
          "name": "Procedures",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/procedures",
              "host": ["{{baseUrl}}"],
              "path": ["api", "procedures"]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Patients",
      "item": [
        {
          "name": "Match patient",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"firstName\": \"\",\n  \"lastName\": \"\",\n  \"phone\": \"\",\n  \"dob\": \"\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/patients/match",
              "host": ["{{baseUrl}}"],
              "path": ["api", "patients", "match"]
            }
          },
          "response": []
        },
        {
          "name": "Create patient",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"firstName\": \"\",\n  \"lastName\": \"\",\n  \"dateOfBirth\": \"\",\n  \"phone\": \"\",\n  \"email\": \"\",\n  \"address\": {\n    \"line1\": \"\",\n    \"city\": \"\",\n    \"state\": \"\",\n    \"zip\": \"\"\n  }\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/patients",
              "host": ["{{baseUrl}}"],
              "path": ["api", "patients"]
            },
            "description": "Two-phase 428 dance: the first send returns 428 with a confirmationToken → set {{confirmationToken}} → send the twin request (\"Create patient (confirm)\") with the identical body plus that token."
          },
          "response": []
        },
        {
          "name": "Create patient (confirm)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"firstName\": \"\",\n  \"lastName\": \"\",\n  \"dateOfBirth\": \"\",\n  \"phone\": \"\",\n  \"email\": \"\",\n  \"address\": {\n    \"line1\": \"\",\n    \"city\": \"\",\n    \"state\": \"\",\n    \"zip\": \"\"\n  },\n  \"confirmationToken\": \"{{confirmationToken}}\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/patients",
              "host": ["{{baseUrl}}"],
              "path": ["api", "patients"]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Slots",
      "item": [
        {
          "name": "Search slots",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/slots?providerId=&locationId=&visitTypeId=&procedureId=&from=&to=",
              "host": ["{{baseUrl}}"],
              "path": ["api", "slots"],
              "query": [
                { "key": "providerId", "value": "" },
                { "key": "locationId", "value": "" },
                { "key": "visitTypeId", "value": "" },
                { "key": "procedureId", "value": "" },
                { "key": "from", "value": "" },
                { "key": "to", "value": "" }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Get slot",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/slots/{{slotId}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "slots", "{{slotId}}"]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Appointments",
      "item": [
        {
          "name": "List appointments",
          "request": {
            "method": "GET",
            "url": {
              "raw": "{{baseUrl}}/api/appointments?patientId={{patientId}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "appointments"],
              "query": [
                { "key": "patientId", "value": "{{patientId}}" }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Book appointment",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"patientId\": \"{{patientId}}\",\n  \"slotId\": \"{{slotId}}\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/appointments",
              "host": ["{{baseUrl}}"],
              "path": ["api", "appointments"]
            },
            "description": "Two-phase 428 dance: the first send returns 428 with a confirmationToken → set {{confirmationToken}} → send the twin request (\"Book (confirm)\") with the identical body plus that token."
          },
          "response": []
        },
        {
          "name": "Book (confirm)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"patientId\": \"{{patientId}}\",\n  \"slotId\": \"{{slotId}}\",\n  \"confirmationToken\": \"{{confirmationToken}}\"\n}"
            },
            "url": {
              "raw": "{{baseUrl}}/api/appointments",
              "host": ["{{baseUrl}}"],
              "path": ["api", "appointments"]
            }
          },
          "response": []
        },
        {
          "name": "Cancel appointment",
          "request": {
            "method": "POST",
            "url": {
              "raw": "{{baseUrl}}/api/appointments/{{appointmentId}}/cancel",
              "host": ["{{baseUrl}}"],
              "path": ["api", "appointments", "{{appointmentId}}", "cancel"]
            }
          },
          "response": []
        },
        {
          "name": "Confirm appointment",
          "request": {
            "method": "POST",
            "url": {
              "raw": "{{baseUrl}}/api/appointments/{{appointmentId}}/confirm",
              "host": ["{{baseUrl}}"],
              "path": ["api", "appointments", "{{appointmentId}}", "confirm"]
            }
          },
          "response": []
        }
      ]
    }
  ]
}
