OURA_API
Library to interact with v2 of the Oura API.
Available as ESM module for Deno, Bun and Node.js through JSR Package and as CommonJS module for Node.js via a NPM package. Deno users can also use the deno.land/x package.
Example usage ESM
Installation
# For Deno
deno add @pinta365/oura-api
# For Bun
bunx jsr add @pinta365/oura-api
# For Node.js
npx jsr add @pinta365/oura-api
Usage
import { Oura, DateFormat } from "@pinta365/oura-api";
// Option 1 - Instantiate with a token in string format.
// Replace 'YOUR_ACCESS_TOKEN' with your actual access token
const accessToken = "YOUR_ACCESS_TOKEN";
const ouraClient = new Oura(accessToken);
// Option 2 - Instantiate with a options object.
// If useSandbox is set to true the accessToken will not be used. This is also the only way to opt into the sandbox environment. See more details about the sandbox further down.
const options = {
accessToken: "YOUR_ACCESS_TOKEN",
useSandbox: false, // Set to true for the sandbox environment
};
const ouraClient = new Oura(options);
const startDate: DateFormat = "2023-01-01";
const endDate: DateFormat = "2023-01-10";
try {
const dailyActivityData = await ouraClient.getDailyActivityDocuments(startDate, endDate);
console.log(`Daily Activity Data: ${JSON.stringify(dailyActivityData, null, 4)}`);
} catch (error) {
console.error(`Error fetching daily activity data: ${error}`);
}
Example usage for CommonJS
Node.js
Install package.
npm install oura_api --save
Code example.
const Api = require("oura_api");
// Option 1 - Instantiate with a token in string format.
// Replace 'YOUR_ACCESS_TOKEN' with your actual access token
const accessToken = "YOUR_ACCESS_TOKEN";
const ouraClient = new Api.Oura(accessToken);
// Option 2 - Instantiate with a options object.
// If useSandbox is set to true the accessToken will not be used. This is also the only way to opt into the sandbox environment. See more details about the sandbox further down.
const options = {
accessToken: "YOUR_ACCESS_TOKEN",
useSandbox: false, // Set to true for the sandbox environment
};
const ouraClient = new Api.Oura(options);
const startDate = "2023-01-01";
const endDate = "2023-01-10";
const example = async () => {
try {
const dailyActivityData = await ouraClient.getDailyActivityDocuments(startDate, endDate);
console.log(`Daily Activity Data: ${JSON.stringify(dailyActivityData, null, 4)}`);
} catch (error) {
console.error(`Error fetching daily activity data: ${error}`);
}
};
example();
Using the Sandbox Environment (For Testing)
The Oura API provides a sandbox environment (Sandbox docs) for testing your application with fake user data that you can access without an Oura account. To use the sandbox, follow these steps:
- Create a Sandbox Client: Opt in for the sandbox endpoints by using the optional useSandbox option when you
instantiate the Oura class.
const ouraSandboxClient = new Oura({ useSandbox: true });
- Make API Calls: Use the
ouraSandboxClient
object to make API calls, just like you would with the regular client.
The API will automatically route your requests to the sandbox environment.const dailyActivityData = await ouraSandboxClient.getDailyActivityDocuments(startDate, endDate);
Documentaion
Library documentation can be found at the JSR documentation page.
Included data scopes for v2 of the API.
Endpoint/Scope | Status |
---|---|
Oura Base | |
Daily Activity | Implemented |
Daily Readiness | Implemented |
Daily Resilience | Implemented |
Daily Sleep | Implemented |
Daily Spo2 | Implemented |
Daily Stress | Implemented |
Enhanced Tag | Implemented |
Heart Rate | Implemented |
Personal Info | Implemented |
Rest Mode Period | Implemented |
Ring Configuration | Implemented |
Session | Implemented |
Sleep | Implemented |
Sleep Time | Implemented |
Tag | DEPRECATED |
Workout | Implemented |
Webhook Subscription | |
List subscription | Implemented |
Create subscription | Implemented |
Update subscription | Implemented |
Delete subscription | Implemented |
Renew subscription | Implemented |
Additional info concerning the webhook API
According to the API docs the webhooks enable you to receive near real-time Oura data updates and are the preferred way to receive the latest data from the Oura API.
I have not been able to fully verify this yet but the subscription workflow has been implemented.
Read the Webhook docs before atempting to use it.
Issues
Issues or questions concerning the library can be raised at the github repository page.
License
This project is licensed under the MIT License - see the LICENSE file for details.