Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

garmin-connect

> 编程语言
Open source

Makes it simple to interface with Garmin Connect to get or set any data point.

193 stars0 likes2 views
WebsiteGitHub

About

Makes it simple to interface with Garmin Connect to get or set any data point.

garmin-connect

v1.6.0 refactor

TODO:

  • New HttpClient class
  • Login and get user token
  • Garmin URLs works with garmin.cn and garmin.com
  • Auto refresh Ouath2 token
  • Oauth1,Oauth2 token import and export.
  • Download Activity, countActivities, getActivities, getActivity, getUserProfile, getUserSettings
  • Upload Activity, delete Activity
  • Implementation of other methods, such as Badge,Workout,Gear etc
  • Handle MFA
  • Handle Account locked
  • Unit test
  • Listeners

If something is not working, please check https://connect.garmin.com/status/ first.

Currently, most of previous features are working, but some of Rest API are not added, such as Gear,Workout,Badge etc. So if you need these features, please add a PR.

All of above work inspired by https://github.com/matin/garth. Many thanks.


A powerful JavaScript library for connecting to Garmin Connect for sending and receiving health and workout data. It comes with some predefined methods to get and set different kinds of data for your Garmin account, but also have the possibility to make custom requests GET, POST and PUT are currently supported. This makes it easy to implement whatever may be missing to suite your needs.

Prerequisites

This library will require you to add a configuration file to your project root called garmin.config.json containing your username and password for the Garmin Connect service.

json
{
    "username": "[email protected]",
    "password": "MySecretPassword"
}

How to install

bash
$ npm install garmin-connect

How to use

javascript
const { GarminConnect } = require('garmin-connect');
// Create a new Garmin Connect Client
const GCClient = new GarminConnect({
    username: '[email protected]',
    password: 'MySecretPassword'
});
// Uses credentials from garmin.config.json or uses supplied params
await GCClient.login();
const userProfile = await GCClient.getUserProfile();

Now you can check userProfile.userName to verify that your login was successful.

Reusing your session(since v1.6.0)

Save token to file and reuse it.

javascript
GCClient.saveTokenToFile('/path/to/save/tokens');

Result:

bash
$ ls /path/to/save/tokens
oauth1_token.json oauth2_token.json

Reuse token:

javascript
GCClient.loadTokenByFile('/path/to/save/tokens');

Or just save your token to db or other storage.

javascript
const oauth1 = GCClient.client.oauth1Token;
const oauth2 = GCClient.client.oauth2Token;
// save to db or other storage
...

Reuse token:

javascript
GCClient.loadToken(oauth1, oauth2);

Reusing your session(deprecated)

This is an experimental feature and might not yet provide full stability.

After a successful login the sessionJson getter and setter can be used to export and restore your session.

javascript
// Exporting the session
const session = GCClient.sessionJson;

// Use this instead of GCClient.login() to restore the session
// This will throw an error if the stored session cannot be reused
GCClient.restore(session);

The exported session should be serializable and can be stored as a JSON string.

A stored session can only be reused once and will need to be stored after each request. This can be done by attaching some storage to the sessionChange event.

javascript
GCClient.onSessionChange((session) => {
    /*
        Your choice of storage here
        node-persist will probably work in most cases 
     */
});

Login fallback

To make sure to use a stored session if possible, but fallback to regular login, one can use the restoreOrLogin method. The arguments username and password are both optional and the regular .login() will be called if session restore fails.

javascript
await GCClient.restoreOrLogin(session, username, password);

Events

  • sessionChange will trigger on a change in the current sessionJson

To attach a listener to an event, use the .on() method.

javascript
GCClient.on('sessionChange', (session) => console.log(session));

There's currently no way of removing listeners.

Reading data

User info is not implemented yet. // TODO: Implement this function

Receive basic user information

javascript
GCClient.getUserInfo();

Social Profile is not implemented yet. // TODO: Implement this function

Receive social user information

javascript
GCClient.getSocialProfile();

Social Connections is not implemented yet. // TODO: Implement this function

Get a list of all social connections

javascript
GCClient.getSocialConnections();

Device info is not implemented yet. // TODO: Implement this function

Get a list of all registered devices including model numbers and firmware versions.

javascript
GCClient.getDeviceInfo();

getActivities(start: number, limit: number, activityType?: ActivityType, subActivityType?: ActivitySubType): Promise

Retrieves a list of activities based on specified parameters.

Parameters:

  • start (number, optonal): Index to start fetching activities.
  • limit (number, optonal): Number of activities to retrieve.
  • activityType (ActivityType, optional): Type of activity (if specified, start must be null).
  • subActivityType (ActivitySubType, optional): Subtype of activity (if specified, start must be null).

Returns:

  • Promise: A Promise that resolves to an array of activities.

Example:

javascript
const activities = await GCClient.getActivities(
    0,
    10,
    ActivityType.Running,
    ActivitySubType.Outdoor
);

getActivity(activity: { activityId: GCActivityId }): Promise

Retrieves details for a specific activity based on the provided activityId.

Parameters:

  • activity (object): An object containing the activityId property.

    • activityId (GCActivityId): Identifier for the desired activity.

Returns:

  • Promise: A Promise that resolves to the details of the specified activity.

Example:

javascript
const activityDetails = await GCClient.getActivity({
    activityId: 'exampleActivityId'
});

News Feed is not implemented yet. // TODO: Implement this function

To get a list of activities in your news feed, use the getNewsFeed method. This function takes two arguments, start and limit, which is used for pagination. Both are optional and will default to whatever Garmin Connect is using. To be sure to get all activities, use this correctly.

javascript
// Get the news feed with a default length with most recent activities
GCClient.getNewsFeed();
// Get activities in feed, 10 through 15. (start 10, limit 5)
GCClient.getNewsFeed(10, 5);

Download original activity data

Use the activityId to download the original activity data. Usually this is supplied as a .zip file.

javascript
const [activity] = await GCClient.getActivities(0, 1);
// Directory path is optional and defaults to the current working directory.
// Downloads filename will be supplied by Garmin.
GCClient.downloadOriginalActivityData(activity, './some/path/that/exists');

Upload activity file

Uploads an activity file as a new Activity. The file can be a gpx, tcx, or fit file. If the activity already exists, the result will have a status code of 409. Upload fixed in 1.4.4, Garmin changed the upload api, the response detailedImportResult doesn't contain the new activityId.

javascript
const upload = await GCClient.uploadActivity('./some/path/to/file.fit');
// not working
const activityId = upload.detailedImportResult.successes[0].internalId;
const uploadId = upload.detailedImportResult.uploadId;

Upload activity image

Uploads an image to activity

javascript
const [latestActivty] = await GCClient.getActivities(0, 1);

const upload = await GCClient.uploadImage(
    latestActivty,
    './some/path/to/file.jpg'
);

Delete activity image

Delete an image from activity

javascript
const [activity] = await GCClient.getActivities(0, 1);
const activityDetails = await GCClient.getActivityDetails(activity.activityId);

await GCClient.deleteImage(
    activity,
    activityDetails.metadataDTO.activityImages[0].imageId
);

getSteps(date?: Date): Promise

Retrieves the total steps for a given date.

Parameters:

  • date (Date, optional): Date of the steps information requested; defaults to today if no date is supplied.

Returns:

  • Promise: A Promise that resolves to the total steps for the specified date.

Example:

javascript
const totalSteps = await GCClient.getSteps(new Date('2020-03-24'));

getSleepData(date: string): Promise

Retrieves all sleep data for a given date

Parameters:

  • date (Date, optional): Date of information requested, this will default to today if no date is supplied

Returns:

  • Promise: A Promise that resolves to an object containing detailed sleep information.

    • dailySleepDTO (object): Information about the user's daily sleep.
      • id (number): The unique identifier of the sleep record.
      • userProfilePK (number): The user's profile identifier.
      • calendarDate (string): The date of the sleep record.
      • ...
    • sleepMovement (array): An array of sleep movement data.
    • remSleepData (boolean): Indicates whether REM sleep data is available.
    • sleepLevels (array): An array of sleep levels data.
    • restlessMomentsCount (number): Count of restless moments during sleep.
    • ...

Example:

javascript
const detailedSleep = await GCClient.getSleepDuration(new Date('2020-03-24'));

getSleepDuration(date: string): Promise: A Promise that resolves to an object containing information about the sleep duration

-   `hours` (string): Number of hours
-   `minutes` (string): Number of minutes

Example:

javascript
const detailedSleep = await GCClient.getSleepDuration(new Date('2020-03-24'));

getDailyWeightData(date?: Date): Promise

Retrieves the daily weight and converts it from grams to pounds.

Parameters:

  • date (Date, optional): Date of information requested. Defaults to the current date.

Returns:

  • Promise: A Promise that resolves to the daily weight converted from grams to pounds.

Throws:

  • Error: If valid daily weight data cannot be found for the specified date.

Example:

javascript
const weightData = await GCClient.getDailyWeightData(new Date('2023-12-25'));

getDailyWeightInPounds(date?: Date): Promise

Retrieves the daily weight in pounds for a given date.

Parameters:

  • date (Date, optional): Date of information requested; defaults to today if no date is supplied.

Returns:

  • Promise: A Promise that resolves to the daily weight in pounds.

Example:

javascript
const weightInPounds = await GCClient.getDailyWeightInPounds(
    new Date('2020-03-24')
);

getDailyHydration(date?: Date): Promise

Retrieves the daily hydration data and converts it from milliliters to ounces.

Parameters:

  • date (Date, optional): Date of the requested information. Defaults to the current date.

Returns:

  • Promise: A Promise that resolves to the daily hydration data converted from milliliters to ounces.

Throws:

  • Error: If valid daily hydration data cannot be found for the specified date or if the response is invalid.

Example:

javascript
const hydrationInOunces = await GCClient.getDailyHydration(
    new Date('2023-12-25')
);

getGolfSummary(): Promise

Retrieves a summary of golf scorecard data.

Returns:

  • Promise: A Promise that resolves to the golf scorecard summary.

Example:

javascript
const golfSummary = await GCClient.getGolfSummary();

getGolfScorecard(scorecardId: number): Promise

Retrieves golf scorecard data for a specific scorecard.

Parameters:

  • scorecardId (number): Identifier for the desired golf scorecard.

Returns:

  • `Pro

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言