Strava Fetch
Fetch procedures for Strava API
An unofficial consumer for the official Strava API using fetch
.
Table of Contents
Install
npm i strava-fetch
Usage
Unless otherwise stated, each procedure takes an object of key-value pairs as its argument, the signature of which conforms to Strava's API Reference for each endpoint.
For example, given Strava's GET /activities/{id}
endpoint which takes the path parameter id
and the query parameter include_all_efforts
, getActivities
would take the following form:
; const activity = await ; console;
This project does not intend to exhaustively document the Strava API itself. For more complete documentation see Strava Developers.
Security
Environment Variables
Some API procedures require properties that may be derived from environment variables rather than being passed as arguments. In the case that an environment variable is defined, the coresponding function argument property may be considered as optional, otherwise it is required. A list of property-variable pairs is provided below.
API Property | Environment Variable |
---|---|
client_id |
STRAVA_CLIENT_ID |
client_secret |
STRAVA_CLIENT_SECRET |
redirect_uri |
STRAVA_REDIRECT_URI |
scrope |
STRAVA_SCOPE |
API
Authorization
/oauth/getAuthorizationUrl
Request Authorization Returns the URL of Strava's OAuth page - http://www.strava.com/oauth/authorize
- where the user will be prompted to give consent to the requesting application.
The funtion takes the following argument signature:
/** @type*/ client_id /** @type*/ redirect_uri /** @type*/ scope
The return of this function should be used to set the client URL.
window.location = getAuthorizationUrl();
Once the user has granted/declined access priviledges, Strava will redirect the user to the URL provided to the redirect_uri
property.
† If any optional property is not provided, the function will attempt to resolve it from the property's corresponding environment variable. See the Security section.
/oauth/exchangeToken
Exchange Authorization Code for Access Token Exchanges the authorization code provided by Strava's authorization UI for an API access code.
The function takes the following argument signature:
/** @type*/ code /** @type*/ client_id /** @type*/ client_secret
† If any property is not provided, the function will attempt to resolve it from the property's corresponding environment variable. See the Security section.
Activities
/activities/createActivity
Create an Activity Creates a manual activity for an athlete.
/activities/getActivityById
Get Activity Returns the given activity that is owned by the authenticated athlete.
/activities/getCommentsByActivityId
List Activity Comments Returns the comments on the given activity.
/activities/getKudoersByActivityId
List Activity Kudoers Returns the athletes who kudoed an activity identified by an identifier.
/activities/getLapsByActivityId
List Activity Laps Returns the laps of an activity identified by an identifier.
/activities/getLoggedInAthleteActivities
List Athlete Activities Returns the activities of an athlete for a specific identifier.
/activities/getZonesByActivityId
Get Activity Zones Summit Feature. Returns the zones of a given activity.
/activities/updateActivityById
Update Activity Updates the given activity that is owned by the authenticated athlete.
Athletes
/athletes/getLoggedInAthlete
Get Authenticated Athlete Returns the currently authenticated athlete.
/athletes/getLoggedInAthleteZones
Get Zones Returns the the authenticated athlete's heart rate and power zones.
/athletes/getStats
Get Athlete Stats Returns the activity stats of an athlete.
/athletes/getLoggedInAthleteZones
Get Zones Returns the the authenticated athlete's heart rate and power zones.
/athletes/updateLoggedInAthlete
Update Athlete Update the currently authenticated athlete.
Clubs
/clubs/getClubActivitiesById
List Club Activities Retrieve recent activities from members of a specific club.
/clubs/getClubAdminsById
List Club Administrators. Returns a list of the administrators of a given club.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.