
Medicare
HealthAccess to the data from the CMS - medicare.gov; The Socrata Open Data API allows you to programmatically access a wealth of open data resources from governments, non-profits, and NGOs around the world.
π Documentation & Examples
Everything you need to integrate with Medicare
π Quick Start Examples
// Medicare API Example
const response = await fetch('https://data.medicare.gov/developers', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);Exploring the Medicare API with JavaScript
The Medicare API provides access to a wealth of healthcare data from the Centers for Medicare & Medicaid Services (CMS). In this blog post, we'll explore how to use the API with JavaScript, using examples to showcase different features and endpoints.
Getting Started β No API Key Required
CMS Medicare provider data is open data and needs no API key. The old data.medicare.gov developer-portal/key flow is retired β the data now lives on the CMS open data platform at data.cms.gov, which you query anonymously.
Datasets are queried through the Datastore API by dataset ID:
// data.cms.gov datastore query β no auth needed
const res = await fetch(
'https://data.cms.gov/provider-data/api/1/datastore/query/{datasetId}?limit=10'
);
const data = await res.json();
Find the exact datasetId and its queryable fields on the dataset's page under the API tab at https://data.cms.gov/provider-data. Note that the old Socrata "four-by-four" IDs (like 4pq5-n9py) and the data.medicare.gov/resource/{id}.json URLs from older tutorials no longer resolve β look up the current dataset ID on the new platform instead.
Rate limits: Anonymous requests are allowed but throttled per IP. Some CMS datasets are still served via Socrata, where registering a free app token (sent as the X-App-Token header) raises your limit β but it's optional, not required to read data.
Example 1: Retrieving Facility Data
In this first example, we'll retrieve data for all long-term care hospitals (LTCHs) in the United States. We'll use the /Facility endpoint to get this data, and we'll filter the results to include only LTCHs.
const API_KEY = "YOUR_API_KEY_HERE";
fetch(
"https://data.medicare.gov/resource/xubh-q36u.json?provider_type=Long%20Term%20Care%20Hospital",
{
headers: {
"X-API-KEY": API_KEY,
},
}
)
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
In this example, we're making a fetch request to the /Facility endpoint, specifying a filter for provider_type to only include LTCHs. We pass our API key in the request headers to authenticate the request. Once we receive the response, we log the data to the console.
Example 2: Retrieving Procedure Data
In this second example, we'll retrieve data for a specific procedure from the Inpatient Prospective Payment System (IPPS) dataset. We'll use the /Procedure endpoint to get this data.
const API_KEY = "YOUR_API_KEY_HERE";
fetch(
"https://data.medicare.gov/resource/4pq5-n9py.json?drg_definition=470%20MAJOR%20JOINT%20REPLACEMENT%20OR%20REATTACHMENT%20OF%20LOWER%20EXTREMITY%20W/O%20MAJOR%20CC/MCC",
{
headers: {
"X-API-KEY": API_KEY,
},
}
)
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
In this example, we're making a fetch request to the /Procedure endpoint, specifying a filter for drg_definition to only include data for the 470 MAJOR JOINT REPLACEMENT OR REATTACHMENT OF LOWER EXTREMITY W/O MAJOR CC/MCC procedure. Once we receive the response, we log the data to the console.
Example 3: Retrieving Provider Data
In this third example, we'll retrieve data for all providers in a specific state. We'll use the /Provider endpoint to get this data, and we'll filter the results to include only providers in the state of California.
const API_KEY = "YOUR_API_KEY_HERE";
fetch(
"https://data.medicare.gov/resource/ukfj-tt6v.json?state=CA",
{
headers: {
"X-API-KEY": API_KEY,
},
}
)
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
In this example, we're making a fetch request to the /Provider endpoint, specifying a filter for state to only include data for California. Once we receive the response, we log the data to the console.
Conclusion
The Medicare API provides a rich source of healthcare data for developers to explore and utilize in their applications. With JavaScript, we can make requests to different endpoints and retrieve data that is specific to our needs. These examples only scratch the surface of what's possible with the Medicare API, and there are many more endpoints and filters to explore.









