Nightscout API
Nightscout API on diab.ninja - REST API v1 and v3 documentation. Retrieve glucose data, integrate applications, and automate CGM monitoring
Nightscout API Your Nightscout instance on diab.ninja provides a full REST API that allows you to retrieve glucose data, integrate your own applications, automate reporting, or build custom dashboards. All without direct access to the database. What is an API? API (Application Programming Interface) is an interface that allows programs to communicate with your Nightscout. Thanks to it, you can, for example, read the current glucose level in your app, send data from a glucose meter, or retrieve treatment history — without logging in through a browser. Nightscout provides two API versions: the classic API v1 (stable, widely supported) and the newer API v3 (lighter, with JWT token support and deduplication). Both work on your diab.ninja instance immediately after launch. You can find interactive Swagger documentation at twoja-nazwa.diab.ninja/api-docs/ Authorization The Nightscout API supports two authentication methods. You can use either depending on your application’s needs. 1. API Secret (HTTP header) Provide your secret password (API Secret set in the Nightscout panel) as the api-secret header. The value must be hashed using the SHA1 algorithm. # HTTP header api-secret: your_sha1_hash Or as a URL parameter https://twoja-nazwa.diab.ninja/api/v1/entries.json?token=your_token 2. Access token (recommended) In Nightscout settings, you can create named tokens with specific permissions (e.g. read-only). This is a safer option when sharing the API with external applications. https://twoja-nazwa.diab.ninja/api/v1/entries.json?token=token-name-secret Note: Never share your API Secret publicly. Use tokens with limited permissions for external integrations. Default access (no authentication) If your instance is configured as public ( AUTH_DEFAULT_ROLES=readable ), some endpoints are available without authorization — read-only. Base URL Send all requests to your instance on diab.ninja: API v1 - twoja-nazwa.diab.ninja/api/v1/ API v3 - twoja-nazwa.diab.ninja/api/v3/ Swagger UI - twoja-nazwa.diab.ninja/api-docs/ Protocol - HTTPS (required) By default, the /entries and /treatments endpoints return the last 10 results from the past 2 days . You can change this with the count parameter. V1 Endpoints Glucose entries - /entries The /entries endpoint contains all readings from your CGM system. SGV data are sensor readings, MBG are glucose meter measurements. GET /api/v1/entries.json - entries list Retrieves a list of glucose entries. By default, the last 10 from 2 days. Available parameters: count – maximum number of results (e.g. count=100 ) find[dateString][$gte] – start date (e.g. 2025-01-01 ) find[dateString][$lte] – end date (use together with $gte ) find[sgv] – filter by specific SGV value in mg/dL token – access token (alternative to header) Example response: [ { "_id": "64f2a3bc...", "type": "sgv", "sgv": 112, "date": 1693900000000, "dateString": "2025-09-05T10:00:00.000Z", "direction": "Flat", "device": "share2" } ] GET /api/v1/entries/sgv.json - sensor readings only Returns only sensor readings (Sensor Glucose Value). Example with date filter: GET /api/v1/entries/sgv.json?find[dateString][$gte]=2025-08-28&find[dateString][$lte]=2025-08-30 GET /api/v1/entries/current - current reading Returns one, the most recent glucose entry. Ideal for widgets and simple integrations. { "sgv": 118, "direction": "FortyFiveUp", "dateString": "2025-09-05T10:05:00.000Z" } POST /api/v1/entries - add entry Adds a new glucose entry. Requires write permissions. [{ "type": "sgv", "sgv": 145, "date": 1693900000000, "direction": "SingleUp", "device": "my-application" }] DELETE /api/v1/entries/:id - delete entry Deletes an entry with the given ID. Requires administrative permissions. ⚠️ The operation is irreversible . Make sure you provide the correct ID. Treatments - /treatments The /treatments endpoint contains therapy-related data: insulin doses, consumed carbohydrates, basal changes, profile switches, and other Care Portal events. GET /api/v1/treatments.json - events list Available filtering parameters: find[eventType] - event type, e.g. Meal Bolus , Temp Basal find[insulin][$gte] - minimum insulin dose (e.g. boluses ≥ 2U: $gte=2 ) count – maximum number of results Example response: [{ "_id": "64f2b1cd...", "eventType": "Meal Bolus", "insulin": 3.5, "carbs": 45, "created_at": "2025-09-05T12:30:00.000Z", "notes": "Lunch" }] POST /api/v1/treatments - add event Adds a new treatment event (bolus, meal, basal change, etc.). { "eventType": "Correction Bolus", "insulin": 1.5, "created_at": "2025-09-05T15:00:00.000Z", "enteredBy": "my-application" } DELETE /api/v1/treatments/:id - delete event Deletes a treatment event with the given ID. Requires write or admin permissions. Treatment profile — /profile The profile is a set of therapy parameters: insulin sensitivity factors (ISF), insulin-to-carb ratio (IC), target glucose level, and basal schedule. These data are used by closed-loop systems (OpenAPS, Loop, AndroidAPS). G
Last updated: