How to make FHIR API calls
After logging into your Epic system, click the "Copy Env" button to generate settings for several shell variables. Be sure to select the correct button depending on whether you're working on Linux or Windows. Afterwards, just open a bash/CMD window, paste in the variable assigments, then try executing the examples below.AI Code Generator New!
Using today's AI platforms you can build your own custom MyChart app without having any software background at all! Enter the following prompt into Google Gemini, and then save and execute the Python program it generates. Try modifying the prompt to download your CBC/CMP results to a CSV file, or retrieve your immunization record. Ask AI to analyze the results and look for anomalies. You'll be amazed what AI can do!"Using the requests package in Python and the FHIR R4 API, write a script that retrieves my complete doctor visit history from an Epic MyChart instance and saves this as a table within an HTML file on disk. Specify the purpose of each visit, the treating doctor, the time, and location. APIBASE, PATIENT, and OAUTH_TOKEN will be retrieved from fetch-my-epic-token.org and passed into the script as environment variables."
Python using fhirpy + fhir.resources New!
According to Google Gemini, the best Python packages in 2026 for reading and parsing FHIR data are fhirpy and fhir.resources. fhirpy makes the API calls, while fhir.resources parses the results. Here's a snippet of Python code that uses the packages to retrieve any glucose observations (LOINC codes 15074-8, 2345-7, 2339-0):import os from fhirpy import SyncFHIRClient from fhir.resources.observation import Observation client = SyncFHIRClient(url=os.getenv('APIBASE'), authorization=f"Bearer {os.getenv('OAUTH_TOKEN')}") results = client.resources("Observation").search(patient=os.getenv('PATIENT'), code="14771-0,2345-7,2339-0").fetch_all() for item in results: reading = Observation.model_construct(**item) date = reading.effectiveDateTime.split("T")[0] value = reading.valueQuantity.value unit = reading.valueQuantity.unit print(f"On {date}: Blood Glucose was {value} {unit}")
Simple Python
Open up Python3 on your machine, and copy/paste the text below.import os import json import requests headers = {"Authorization" : "Bearer " + os.getenv("OAUTH_TOKEN"), "Accept" : "application/json+fhir"} url = os.getenv("APIBASE") + "/Observation?_count=3&patient=" + os.getenv("PATIENT") + "&category=vital-signs" rsp = requests.get(url, headers=headers) print(json.dumps(rsp.json(), indent=4))
CLI using curl
Copy/paste the correct curl command into your terminal, and hit enter.# Linux: curl -H "Authorization: Bearer ${OAUTH_TOKEN}" -H "Accept: application/json+fhir" "${APIBASE}/Observation?_count=3&patient=${PATIENT}&category=vital-signs" :: Windows: curl -H "Authorization: Bearer %OAUTH_TOKEN%" -H "Accept: application/json+fhir" "%APIBASE%/Observation?_count=3&patient=%PATIENT%&category=vital-signs"
Javascript
If you have node.js installed on your machine you can try executing the fetch command in that environment. Otherwise, it's just as easy to use the Javascript engine built into the browser. Copy/paste the text below into an html file, open it with a browser, populate the variables on the form, and click "Try It!".<html> <head> <link rel="stylesheet" href="https://fetch-my-epic-token.org/style.min.css"> </head> <body> <input id="apibase" type="text" placeholder="APIBASE" size=80><br> <input id="patient" type="text" placeholder="PATIENT" size=80><br> <textarea id="oauth_token" type="text" placeholder="OAUTH_TOKEN" cols=80></textarea><br> <button onclick='getObservations();'>Try It!</button> <div id="fhir_rsp"></div> <script> function getObservations() { fetch(apibase.value + '/Observation?_count=3&patient=' + patient.value + '&category=vital-signs', {headers: { "Authorization": "Bearer " + oauth_token.value, "Accept": "application/json+fhir"}} ).then(response => response.json()).then(json => fhir_rsp.innerHTML = '<pre>' + JSON.stringify(json,null,4)+ '</pre>') } </script> </body> </html>