
openFDA
HealthPublic FDA data about drugs, devices, and foods. API provides end points against events / product labelling / NDC directory / recall Enforcement Reports. The goal of the project is to create easy access to public data, to create a new level of openness and accountability, to ensure the privacy and security of public FDA data, and ultimately to educate the public and save lives. The concept was to index high-value, high priority and scalable public-access data, format and document that data in developer and consumer-friendly standards, and make that data available via a public-access portal that enables developers to quickly and easily use it in applications.
📚 Documentation & Examples
Everything you need to integrate with openFDA
🚀 Quick Start Examples
// openFDA API Example
const response = await fetch('https://open.fda.gov', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
Using the FDA Open API with JavaScript
The FDA Open API provides access to various datasets related to drug information, recalls, adverse events, and more. In this guide, we will explore how to use the FDA Open API with JavaScript, using example code snippets.
Setup
Before we can start using the FDA Open API with JavaScript, we need to obtain an API key. Follow these steps to obtain an API key:
- Go to the FDA Open API website and click on "Get API Key" in the top-right corner.
- Create an account or sign in if you already have one.
- Follow the steps to create an API key.
Once you have obtained an API key, you can start using the API.
Using the API
There are several API endpoints provided by the FDA Open API, each related to specific data sets. You can explore the available endpoints and their documentation on the API documentation page.
Retrieving drug information
To retrieve information about a specific drug, we can use the /drug/label.json
endpoint. Here is an example code snippet in JavaScript:
const api_key = 'YOUR_API_KEY';
const drug_name = 'aspirin';
fetch(`https://api.fda.gov/drug/label.json?search=${drug_name}&api_key=${api_key}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
This code uses the fetch
function to make a GET request to the /drug/label.json
endpoint, with the search
parameter set to the value of drug_name
. We also include the api_key
parameter in the URL. The response is parsed as JSON and logged to the console.
Retrieving adverse events
To retrieve information about adverse events related to a specific drug, we can use the /drug/event.json
endpoint. Here is an example code snippet in JavaScript:
const api_key = 'YOUR_API_KEY';
const drug_name = 'aspirin';
fetch(`https://api.fda.gov/drug/event.json?search=${drug_name}&api_key=${api_key}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
This code is similar to the previous example, but with a different endpoint and different search parameters. The response will include data about adverse events related to the specified drug.
Conclusion
In this guide, we explored how to use the FDA Open API with JavaScript. We covered information retrieval for both drugs and adverse events. By following the examples presented in this guide, you should be able to start building applications that utilize the FDA Open API.
📊 30-Day Uptime History
Daily uptime tracking showing online vs offline minutes