> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackone.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Epic with OAuth 2.0 (Client Credentials) – StackOne Hub

> Link a Epic account in the StackOne Hub using OAuth 2.0 (Client Credentials). End-user guide to authorize the integration and start using Epic actions.

> [!WARNING]
>
> The person linking this account registers its own Backend Systems app and key pair, which needs an Epic on FHIR developer account. For production, each health system must activate your client ID and map it to an Epic user before calls work. Epic's sandbox needs neither.

## Find your FHIR R4 Base URL

Your **FHIR R4 Base URL** is the address of the health system's Epic FHIR R4 server. Leave it empty to connect to Epic's sandbox.

<ul>
  <li>Find the health system's address under **Production Endpoints** in Epic's [endpoint directory](https://open.epic.com/MyApps/Endpoints), or ask the health system's Epic team.</li>
  <li>Format: `https://{host}/{path}/api/FHIR/R4`, with no trailing slash</li>
  <li>Example: if the directory lists `https://fhir.example-health.org/FHIR/api/FHIR/R4/`, your **FHIR R4 Base URL** is `https://fhir.example-health.org/FHIR/api/FHIR/R4`</li>
</ul>

## Host your key set

Your **Private Key (PKCS8 PEM)** for this account comes from a key pair you create. Epic reads its public key from a JWK Set URL that uses HTTPS, is publicly reachable and needs no sign-in.

**1. Generate the key pair**

Run these commands to create a 2048-bit RSA private key, a copy of it in PKCS8 PEM format, and a JSON Web Key Set (JWKS) with its public key.

```bash theme={null}
openssl genrsa -out privatekey.pem 2048
openssl pkcs8 -topk8 -nocrypt -in privatekey.pem -out privatekey.p8
node -e "const k=require('crypto').createPublicKey(require('fs').readFileSync('privatekey.pem')).export({format:'jwk'});console.log(JSON.stringify({keys:[{...k,kid:'stackone-1',alg:'RS256',use:'sig'}]}))" > jwks.json
```

<ul>
  <li>Run them once for non-production and again, in another folder, for production. Epic needs a different JWK Set URL for each.</li>
</ul>

**2. Publish the key set**

Host each `jwks.json` at its own HTTPS address that anyone can open without signing in, such as a public storage bucket or your website.

<ul>
  <li>Open each address in a private browser window and check that it shows the key set.</li>
</ul>

## Register a Backend Systems app

Your Backend Systems app issues the **Client ID** you enter for this account and sets which Epic APIs it may call.

**1. Create the app**

Sign in to [Epic on FHIR](https://fhir.epic.com) and open **Build Apps**.

<ul>
  <li>Click **Create**.</li>
  <li>**Application Name**: `StackOne`</li>
  <li>Select **Backend Systems** as the user type.</li>
</ul>

**2. Set up OAuth 2.0**

Backend Systems apps use OAuth 2.0 to get access tokens.

<ul>
  <li>Check **Use OAuth 2.0**.</li>
  <li>**App FHIR Version**: **R4**</li>
</ul>

**3. Add the APIs**

Epic grants the app only the APIs you add, and health systems review the list before they activate the app.

<ul>
  <li>Check **Incoming API**.</li>
  <li>Under **Incoming APIs**, add each of these APIs:</li>
  <li>**Patient.Search (Demographics) (R4)**</li>
  <li>**Patient.Read (Demographics) (R4)**</li>
  <li>**AllergyIntolerance.Search (Patient Chart) (R4)**</li>
  <li>**AllergyIntolerance.Read (Patient Chart) (R4)**</li>
  <li>**Condition.Search (Problems) (R4)**</li>
  <li>**Condition.Read (Problems) (R4)**</li>
  <li>**Condition.Search (Encounter Diagnosis) (R4)**</li>
  <li>**Condition.Read (Encounter Diagnosis) (R4)**</li>
  <li>**Condition.Search (Health Concerns) (R4)**</li>
  <li>**Condition.Read (Health Concerns) (R4)**</li>
  <li>**Condition.Search (Medical History) (R4)**</li>
  <li>**Condition.Read (Medical History) (R4)**</li>
  <li>**MedicationRequest.Search (Signed Medication Order) (R4)**</li>
  <li>**MedicationRequest.Read (Signed Medication Order) (R4)**</li>
  <li>**MedicationAdministration.Search (R4)**</li>
  <li>**MedicationAdministration.Read (R4)**</li>
  <li>**Observation.Search (Labs) (R4)**</li>
  <li>**Observation.Read (Labs) (R4)**</li>
  <li>**Observation.Search (Vital Signs) (R4)**</li>
  <li>**Observation.Read (Vital Signs) (R4)**</li>
  <li>**Observation.Search (Social History) (R4)**</li>
  <li>**Observation.Read (Social History) (R4)**</li>
  <li>**Observation.Search (Flowsheets) (R4)**</li>
  <li>**Observation.Read (Flowsheets) (R4)**</li>
  <li>**DiagnosticReport.Search (Results) (R4)**</li>
  <li>**DiagnosticReport.Read (Results) (R4)**</li>
  <li>**Binary.Read (Labs) (R4)**</li>
  <li>**Binary.Read (Radiology Results) (R4)**</li>
  <li>**Procedure.Search (Orders) (R4)**</li>
  <li>**Procedure.Read (Orders) (R4)**</li>
  <li>**Procedure.Search (Surgeries) (R4)**</li>
  <li>**Procedure.Read (Surgeries) (R4)**</li>
  <li>**Immunization.Search (Patient Chart) (R4)**</li>
  <li>**Immunization.Read (Patient Chart) (R4)**</li>
  <li>**Encounter.Search (Patient Chart) (R4)**</li>
  <li>**Encounter.Read (Patient Chart) (R4)**</li>
  <li>**Appointment.Search (Appointments) (R4)**</li>
  <li>**Appointment.Read (Appointments) (R4)**</li>
  <li>**DocumentReference.Search (Clinical Notes) (R4)**</li>
  <li>**DocumentReference.Read (Clinical Notes) (R4)**</li>
  <li>**Binary.Read (Clinical Notes) (R4)**</li>
  <li>**ServiceRequest.Search (Orders) (R4)**</li>
  <li>**ServiceRequest.Read (Orders) (R4)**</li>
  <li>**Coverage.Search (Patient Insurance Information) (R4)**</li>
  <li>**Coverage.Read (Patient Insurance Information) (R4)**</li>
  <li>**Practitioner.Search (Organizational Directory) (R4)**</li>
  <li>**Practitioner.Read (Organizational Directory) (R4)**</li>
  <li>**CarePlan.Search (Longitudinal) (R4)**</li>
  <li>**CarePlan.Read (Longitudinal) (R4)**</li>
  <li>**CarePlan.Search (Encounter) (R4)**</li>
  <li>**CarePlan.Read (Encounter) (R4)**</li>
  <li>**CarePlan.Search (Outpatient) (R4)**</li>
  <li>**CarePlan.Read (Outpatient) (R4)**</li>
  <li>**CareTeam.Search (Longitudinal CareTeam) (R4)**</li>
  <li>**CareTeam.Read (Longitudinal CareTeam) (R4)**</li>
  <li>**Goal.Search (Patient) (R4)**</li>
  <li>**Goal.Read (Patient) (R4)**</li>
  <li>**Device.Search (Implants) (R4)**</li>
  <li>**Device.Read (Implants) (R4)**</li>
  <li>**FamilyMemberHistory.Search (R4)**</li>
  <li>**FamilyMemberHistory.Read (R4)**</li>
  <li>**ExplanationOfBenefit.Search (Claim) (R4)**</li>
  <li>**ExplanationOfBenefit.Read (Claim) (R4)**</li>
  <li>**QuestionnaireResponse.Search (Patient-Entered Questionnaires) (R4)**</li>
  <li>**QuestionnaireResponse.Read (Patient-Entered Questionnaires) (R4)**</li>
  <li>**AllergyIntolerance.Create (Patient Chart) (R4)**</li>
  <li>**Condition.Create (Problems) (R4)**</li>
  <li>**DocumentReference.Create (Clinical Notes) (R4)**</li>
  <li>**Observation.Create (Vital Signs) (R4)**</li>
  <li>**Observation.Create (Flowsheets) (R4)**</li>
  <li>**Patient.$match (Patient Match) (R4)</strong></li>   <li><strong>Patient.$summary (International Patient Summary) (R4)**</li>
  <li>**Appointment.$find (STU3)</strong></li>   <li><strong>Appointment.$book (STU3)**</li>
  <li>**Bulk Data Kick-off**</li>
  <li>**Bulk Data Status Request**</li>
  <li>**Bulk Data File Request**</li>
  <li>**Bulk Data Delete Request**</li>
</ul>

**4. Add the JWK Set URLs**

Epic prompts for a non-production and a production JWK Set URL.

<ul>
  <li>**Non-production JWK Set URL**: the address of your non-production `jwks.json`.</li>
  <li>**Production JWK Set URL**: the address of your production `jwks.json`.</li>
  <li>Click **Save**.</li>
  <li>Note: Epic syncs a new app to its sandbox within about an hour.</li>
</ul>

**5. Set the app ready for production**

A health system can request the app only after you mark it ready for production. Epic's sandbox skips this step.

<ul>
  <li>On **Build Apps**, select the app.</li>
  <li>Check the box to accept the Terms and Conditions.</li>
  <li>Click **Save and Ready for Production**. Epic locks the API list from then on.</li>
  <li>Give the health system your **Production Client ID** so they can request the app.</li>
</ul>

**6. Activate the app for a health system**

Activate the app once the health system's request arrives.

<ul>
  <li>Click **Review and Manage Downloads** for the app.</li>
  <li>Select the environment type, non-production before production.</li>
  <li>Select the **JWK Set URL** option. Epic uses the key set address you gave for that environment.</li>
  <li>Click **Activate**.</li>
</ul>

**7. Copy the credentials**

Use the client ID and key file for the environment you are connecting. Copy the whole key file, including its BEGIN and END lines.

<ul>
  <li>**Sandbox:** Copy the **Non-Production Client ID** across. Copy the whole non-production `privatekey.p8` across to **Private Key (PKCS8 PEM)**.</li>
  <li>**Production:** Copy the **Production Client ID** across. Copy the whole production `privatekey.p8` across to **Private Key (PKCS8 PEM)**.</li>
</ul>

## Link the Account

**1. Connect**

<ul>
  <li>Click **Connect**.</li>
  <li>If applicable, the provider will redirect you to a sign-in or authorization page. Complete the provider's authorization flow.</li>
  <li>Once authorization is successful, you will see a confirmation popup.</li>
</ul>

**2. Use Actions**

Connect an AI platform to the linked account's actions. See [AI Platforms](https://docs.stackone.com/ai-platforms/overview.md).

Other ways to call actions are listed in [Protocols & SDKs](https://docs.stackone.com/connect/protocols-and-sdks.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.