Tags: healthcare, epic, fhir, anypoint-exchange, api-governance, hipaa, interoperability
Epic Interconnect API Scanner
Deliverable: A scheduled Mule 4 app, epic-api-scanner, that discovers every FHIR and proprietary web service on an Epic Interconnect instance, publishes each one to Anypoint Exchange as a tagged asset (with a generated OAS spec where possible), deprecates services that disappear, and can hold new APIs as pending until the platform team approves them and API Manager policies are applied. No scanner SDK required.
Objective: Health systems run dozens of Epic APIs across PRD, POC and TST, and nobody has an accurate list. Integration teams rebuild connections that already exist, security can't say which APIs carry PHI, and Epic's quarterly upgrades silently add or retire endpoints. This blueprint makes the Interconnect inventory self-maintaining: one source of truth in Exchange, refreshed on a schedule, with PHI-bearing APIs flagged and new ones blocked until approved.
What's Getting Built
- Scanner Process API (Process API) — runs scheduled scans for each configured Epic environment, orchestrates discovery, diff and governance, publishes and deprecates assets in Anypoint Exchange directly through the Exchange API, creates API Manager instances and policies for approved assets (governed path), and exposes the ops endpoints itself (no separate Experience layer) ·
POST /scans, GET /scans, GET /scans/{scanId}, GET /inventory, GET /inventory/{assetId}, GET /approvals, POST /approvals/{assetId}
- Epic discovery client (System API, internal) — SMART backend-services token, CapabilityStatement read, proprietary service probing ·
GET /api/FHIR/R4/metadata, GET /.well-known/smart-configuration, HEAD {servicePath}
- Anypoint Exchange (target) — receives published, tagged and deprecated assets from the Process API ·
GET /exchange/api/v2/assets, POST /exchange/api/v2/organizations/{orgId}/assets/{groupId}/{assetId}/{version}, PATCH .../status
- Anypoint API Manager (target, optional) — receives API instances and policies from the Process API for approved assets ·
POST /apimanager/api/v1/organizations/{orgId}/environments/{envId}/apis
Prerequisites
- Epic app registration (the long pole, 2 to 8 weeks): a Backend Services app in Epic's developer portal, activated for each health system by the customer's Epic team, with the narrowest system scopes they approve. You get a client ID per environment.
- Key pair: RS384. Public key (or JWK Set URL) registered with Epic; private key in Mule Secure Properties or a secrets manager.
- Interconnect base URLs per environment, e.g.
https://{epic-host}/Interconnect-PRD-FHIR/, plus the enabled-services export from the customer's Interconnect team, the only reliable source for proprietary services.
- Anypoint Connected App (client credentials) with Exchange Contributor, and optionally Manage APIs Configuration / Manage Policies, in the target business group.
- Network path: a CloudHub 2.0 Private Space or Runtime Fabric that can reach Interconnect. Epic usually sits behind a VPN, and that request often takes longer than the build.
- Security sign-off that the scanner reads metadata only, never patient data.
Choose your path
- Exchange-only inventory — choose this when the goal is visibility: a searchable catalog of what Epic exposes. Lowest risk, needs only Exchange scopes.
- Governed registry — choose this when you also need to control use: new APIs land as
pending, the platform team approves them through /approvals, and the scanner then creates API Manager instances with client-ID enforcement and rate limits.
- Try it on the Epic sandbox — choose this when you only have open.epic access and want to prove the scanner end to end before a customer environment exists. See the next section.
Try it on the Epic sandbox
Epic's public sandbox at fhir.epic.com needs no health system, VPN or customer approval, so the FHIR half of the scanner runs against it on day one.
- Check it first:
GET https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/metadata is public; curl it before you have credentials.
- Register an app: on fhir.epic.com open Build Apps, create a Backend Systems app and select the R4 APIs. The non-production client ID is issued right away but can take a few hours to work;
invalid_client until then is normal.
- Key and runtime: register your RS384 public key on the app page. The sandbox is public, so Studio, Code Builder or CloudHub without a Private Space all work.
- Target: publish into a disposable business group or trial org.
- Config: one environment named
SANDBOX, baseUrl: https://fhir.epic.com/interconnect-fhir-oauth, tokenUrl: {baseUrl}/oauth2/token, dryRun: true until the report looks right.
The sandbox has no proprietary services and its CapabilityStatement rarely changes, so cover those paths with test doubles:
- Probing: a seed list pointing at a local mock (Mule listener or WireMock) returning
401, 405 and 404. The first two must be reported present, the third missing.
- Change and deprecation: a test switch serves a saved CapabilityStatement with one resource added, then removed. Expect one new minor version, then deprecation only after
deprecateAfterMisses runs.
- Outage: point
baseUrl at an unreachable host. The scan reports errors and deprecates nothing.
The sandbox can't prove per-customer environments, network access to an on-prem Interconnect, the customer's scope grants, or their real proprietary-services list. Those move to Phase 1.
Architecture
1. Scaffold the project and configuration
2. Authenticate to Epic (SMART Backend Services)
- Client assertion JWT:
iss = sub = clientId, aud = tokenUrl, unique jti, exp = now + 4 min (Epic rejects over 5), signed RS384 with a small Java helper (DataWeave can't sign).
POST {tokenUrl} with grant_type=client_credentials, client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer, client_assertion={jwt}.
- Cache the token in Object Store for
expires_in - 60s.
- Why: it's the only Epic auth model with no user in the loop, and what Epic security teams approve for background services.
3. Discover FHIR APIs
GET {baseUrl}/api/FHIR/R4/metadata (Accept: application/fhir+json); also STU3 and DSTU2 if enabled. A 404 means that version is off, not an error.
- From
rest[0].resource[] take type, interaction[].code, searchParam[], operation[], supportedProfile[]. Record scopes_supported from /.well-known/smart-configuration.
- Granularity: default to one asset per FHIR version per environment (
epic-fhir-r4-prd). One per resource is more searchable but creates 150+ assets; make it configurable.
4. Discover proprietary Epic web services
- Services under
/api/epic/... have no discovery endpoint, so load a seed list (id, name, path, protocol, method, phi, owner) built from the enabled-services export.
- Probe each with
HEAD, falling back to OPTIONS. Treat 401/403/405 as present and only 404 or a connection failure as missing. Never send a request body.
- Why: a stale seed list gets reported, not published.
5. Normalize and generate specs (DataWeave)
- Map everything to one model:
assetId (lowercase, hyphens only), name, type (rest-api for FHIR, http-api for endpoint-only), baseUrl, environment, phi, scopes, resources, and a SHA-1 hash of rest[0].resource only.
- For FHIR, generate OAS 3.0:
/{Resource} and /{Resource}/{id} paths, operations from interaction (read → GET /{id}, search-type → GET with searchParam query params, create → POST), and an OAuth2 client-credentials security scheme.
6. Diff against the last known state
- Persistent Object Store v2 holds
{assetId → hash, version, lastSeen, misses}.
- New: publish
1.0.0. Changed: publish a new minor version so consumers keep the old spec. Unchanged: no-op. Missing: increment misses; deprecate at deprecateAfterMisses.
- If state is lost, rebuild it from Exchange (
GET /exchange/api/v2/assets?organizationId={orgId}&search=epic-, paged) so a wiped store never causes mass republishing.
7. Publish to Anypoint Exchange
- The Process API calls the Exchange API itself. Exchange is the only consumer and nothing else reuses the calls, so a separate System API would add a deployment without adding value.
- Platform token:
POST https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token with Connected App credentials; cache it.
- Publish as
multipart/form-data to POST /exchange/api/v2/organizations/{orgId}/assets/{groupId}/{assetId}/{version} with name, type, properties.mainFile, properties.apiVersion and files.oas.json (omit files for http-api). Check field names against current Exchange API docs for your control plane.
- Then set tags (
epic, fhir, r4, prd, phi, scanned) and custom fields (source, environment, phi, lastScanned).
- Deprecate with
PATCH .../{version}/status and {"status":"deprecated"}.
- Retry 429/5xx three times with backoff; treat 409 on publish as success.
8. Governance (governed path)
- New assets get
approvalStatus=pending. GET /approvals lists them with environment, PHI flag and scopes, and each scan report flags them.
POST /approvals/{assetId} (client ID enforcement, platform team's app only) takes {decision, approvedBy, note} and writes it to the audit log.
- approved: the Process API calls the API Manager API directly to create the instance from the Exchange asset and apply Client ID Enforcement, Rate Limiting and JWT Validation.
- rejected: set
approvalStatus=rejected and tag blocked.
- Why: discovery doesn't equal permission. An unapproved API is visible but nobody can get a contract for it.
9. Ops endpoints and observability
- The Process API exposes the ops endpoints itself, secured with client ID enforcement. The only callers are the platform team and its tooling, so a separate Experience API would add a deployment without adding value.
POST /scans with { "environment": "PRD", "dryRun": true } returns 202 and a scanId, and runs async on a VM queue; returns 409 if that environment is already scanning.
- Keep 90 days of scan reports. Alert when errors > 0, the Epic token fails twice in a row, or more than 10% of the inventory would be deprecated (usually a broken seed list or network, not real retirements).
- CloudHub 2.0, 0.1 vCore, 1 replica, in a Private Space with VPN or peering to Epic.
10. Security and compliance
- HIPAA: metadata only. The Epic HTTP requester allowlists
/metadata, /.well-known/*, the token URL and HEAD to seeded paths, so no PHI endpoint can be called.
- Least privilege: narrowest Epic scopes; Connected App scoped to one business group.
- Secrets: private key in Secure Properties or a vault, rotated yearly. TLS 1.2+ with the Epic CA pinned.
- Audit: log scan ID, environment, counts, asset IDs and actions. Never log tokens, JWT assertions or Epic response bodies.
Sample payload — scan report (GET /scans/{scanId})
{
"scanId": "scn-2026-10-15-prd-0300",
"environment": "PRD",
"dryRun": false,
"summary": { "discovered": 46, "new": 2, "changed": 1, "unchanged": 42, "deprecated": 1, "errors": 0 },
"actions": [
{ "assetId": "epic-fhir-r4-prd", "action": "changed", "fromVersion": "1.3.0", "toVersion": "1.4.0",
"detail": "Added resources: CarePlan, Goal" },
{ "assetId": "epic-svc-get-patient-appointments-prd", "action": "new", "version": "1.0.0",
"approvalStatus": "pending" },
{ "assetId": "epic-svc-legacy-orders-prd", "action": "deprecated", "misses": 3 }
]
}
Deterministic checks
POST /scans returns 202 with a scanId; a second call for the same environment mid-scan returns 409.
- Two scans against an unchanged Epic stub: the second has
new=0, changed=0 and makes zero Exchange publish calls.
- One added FHIR resource publishes exactly one new minor version; the previous version remains.
- A service missing for fewer than
deprecateAfterMisses runs is not deprecated; at the threshold it is deprecated exactly once.
- Exchange 409 counts as success; 429/5xx retry three times, then the asset is marked
error and the scan continues.
- The Epic requester rejects non-allowlisted paths (unit-tested).
dryRun=true makes zero writes to Exchange or API Manager.
- Pending or rejected assets never get an API Manager instance.
- MUnit suite in
src/test/munit/ passes with ≥ 80% flow coverage, mocking Epic, Exchange and API Manager.
Testing and validation
- Happy path: scan the Epic sandbox into a sandbox business group; the asset appears with a browsable OAS spec and correct tags.
- The edge case that breaks naive builds: a 503 on
/metadata for one run. A naive scanner sees zero resources and deprecates everything. Failed discovery must be error, never "empty".
- Second trap: proprietary services answering
HEAD with 405 or 401 must count as present.
- Mapping: OAS paths must match the CapabilityStatement resource list exactly; the customer's Interconnect team reviews the proprietary inventory once.
Phased rollout
Phase 0 — Prove it on the Epic sandbox (optional)
- Dry run, then live publish into a disposable business group, with the mock seed list. De-risks the build while Epic app approval is pending.
Phase 1 — Connect (weeks 1–2, gated by Epic app approval)
- App activated in TST; token exchange works;
/metadata readable over the VPN. One manual Exchange publish succeeds.
Phase 2 — Map and validate (weeks 3–4)
- Full TST scan in dry run, then live into a sandbox business group. Seed list reconciled; MUnit green; failure handling verified with fault injection.
Phase 3 — Production (weeks 5–6)
- Scheduled PRD scans into the production business group; governed path enabled if chosen. Runbook and alerts handed to the platform team.
Success metrics
- Inventory coverage: 100% of services in the enabled-services export appear in Exchange.
- Time to discover a new Epic API: the next scheduled scan, down from whenever someone notices.
- Duplicate builds avoided: fewer new point-to-point Epic integrations, tracked through Exchange reuse metrics.
- Ungoverned PHI APIs: zero
phi=true assets without an API Manager instance on the governed path.
- Scanner health: ≥ 99% scan success, under 5 minutes per run, no false-positive deprecations.
Troubleshooting
- Token call returns
invalid_client — Likely cause: app not activated for this environment, wrong aud, RS256 instead of RS384, or clock skew. Fix: confirm activation, set aud to the exact token URL, sign RS384, sync NTP.
- Whole inventory deprecated overnight — Likely cause: discovery failed and was treated as empty, or
deprecateAfterMisses is 1. Fix: restore with PATCH status=published; make failed discovery an error.
- Every scan republishes every asset — Likely cause: the hash includes volatile fields (
date, id, meta) or Object Store isn't persistent. Fix: hash only rest[0].resource; use persistent Object Store v2.
- Exchange publish returns 400 or 403 — Likely cause:
mainFile doesn't match the uploaded file, an invalid assetId, or the Connected App lacks Exchange Contributor in that business group. Fix: lowercase hyphenated IDs, matching file names, scope granted on the right business group.
- Proprietary services all reported missing — Likely cause: a base URL prefix mismatch or a proxy blocking HEAD. Fix: set the proprietary base URL separately; fall back to OPTIONS.