Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including endomondo-api-handler with all npm packages installed. Try it out:

var endomondoApiHandler = require("endomondo-api-handler")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

endomondo-api-handler v7.3.0

Unofficial handler for Endomondo API

Endomondo API handler

npm version renovate-app Known Vulnerabilities codecov travis

This a handler for unofficial Endomondo API, which is used on their web app and mobile app. It allows you to read various of information and update them. This library is focused on searching, updating and creating workouts. Other endpoints you can find by sniffing your browser. Cooperation is welcome.

The library is based on my PHP library that do the similar.

The library is compiled for node 9.6. You are using this library on your own danger.

How it works

I use a library for handling REST API request - rest-api-handler. It is based on browser fetch feature so it needs polyfill.

Since this is not official API you need to use your login and password to log in.

How to use

Install npm library:

npm install endomondo-api-handler --save

Include fetch polyfill. I recommend cross-fetch:

import 'cross-fetch/polyfill';

There are two APIs. One is based on the web app and the second on the mobile app. You need Mobile API to create new workouts. Regular API will do everything else.

Authentize

If you need to create new workouts you need to authentize both to API and Mobile API.

const { Api, MobileApi } = require('endomondo-api-handler');

(async () => {
    const api = new Api();
    const mobileApi = new MobileApi();

    await Promise.all([
        api.login(login, password),
        mobileApi.login(login, password),
    ]);

    console.log(await api.get('rest/session'));
})();

Getting workout/s

To get single workout use getWorkout method:

const workout = await api.getWorkout(775131509);

Search for workouts:

const { DateTime } = require('luxon');

const { workouts } = await api.getWorkouts({
    after: DateTime.fromObject({
        year: 2018,
        month: 3,
        day: 1,
    }),
    limit: 2,
});
console.log(workouts);

Create a new workout

To create workout, use WorkoutFactory and MobileApi:

const { DateTime, Duration } = require('luxon');
const math = require('mathjs');
const { Point, Workout } = require('endomondo-api-handler');

const start = DateTime.fromObject({
    year: 2018,
    month: 3,
    day: 27,
    hour: 5,
    minute: 2,
});

const workout = Workout.get(
    Workout.SPORT.RUNNING,
    start,
    Duration.fromObject({ minutes: 3 }),
    math.unit(3, 'km'),
    [
        Point.get(start, 50.02957153, 14.51805568),
        Point.get(start.plus({ minutes: 1 }), 50.03057153, 14.52205568),
        Point.get(start.plus({ minutes: 2 }), 50.03357153, 14.53805568),
    ],
);

const workoutId = await mobileApi.createWorkout(workout);

Export your workouts to GPX

require('cross-fetch/polyfill');
const fs = require('fs');
const { Api } = require('endomondo-api-handler');

const api = new Api();

(async () => {
    await api.login(LOGIN, PASSWORD);

    await api.processWorkouts({}, async (workout) => {
        console.log(workout.toString());
        if (workout.hasGPSData()) {
            fs.writeFileSync(`tmp/${workout.getId()}.gpx`, await api.getWorkoutGpx(workout.getId()), 'utf8');
        }
    });
})();

Note - In old example gpx was generated by data from json response of Endomondo. I changed it to use getWorkoutGpx method which download gpx file directly from Endomondo and it's not processed by app.

Note 2 - When you are exporting tcx export of workout (by using method api.getWorkoutTcx) Endomondo sometimes creates workouts with duplicit IDs. To avoid this you can process tcx with simple replace:

tcx.replace(/<Id>([0-9]|-|T|:|Z)*<\/Id>/g, `<Id>${workout.getStart().toISO()}</Id>`)
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free