### Quick Start with strava-v3 Promise API in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This example demonstrates a quick start using the Promise-based API. It initializes the `strava-v3` library, configures it (placeholder for actual config), and then fetches the current athlete's data asynchronously using `await`, logging the result. Requires an `access_token` to be configured. ```javascript const strava = require('strava-v3') strava.config({...}) const payload = await strava.athlete.get({}) console.log(payload) ``` -------------------------------- ### Installing strava-v3 Node.js Library Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This command installs the `strava-v3` Node.js library using npm, making it available for use in your project. It's the first step to integrate with the Strava API. ```bash npm install strava-v3 ``` -------------------------------- ### Example General API Usage with Callback API in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This example demonstrates fetching a specific athlete's data using the Callback API. It passes an `id` parameter and processes the `payload` or `err` within the callback function, also providing access to `limits` for rate limit tracking. ```javascript var strava = require('strava-v3'); strava.athletes.get({id:12345},function(err,payload,limits) { //do something with your payload, track rate limits }); ``` -------------------------------- ### Handling Strava API Rate Limits with Callbacks in Node.js Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This example demonstrates how to retrieve and process Strava API rate limit information using a callback-based approach. The `strava.athlete.get` method is called with an access token, and the callback function receives `err`, `payload`, and `limits` objects, allowing for direct inspection of short-term and long-term usage and limits. ```JavaScript const strava = require('strava-v3'); strava.athlete.get({'access_token':'abcde'},function(err,payload,limits) { //do something with your payload, track rate limits console.log(limits); /* output: { shortTermUsage: 3, shortTermLimit: 600, longTermUsage: 12, longTermLimit: 30000 } */ }); ``` -------------------------------- ### Quick Start with strava-v3 Callback API in JavaScript (Deprecated) Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet illustrates the deprecated Callback API for fetching athlete data. It makes an API call and handles the response or error within a callback function. While functional, the Promise API is recommended for new development. ```javascript const strava = require('strava-v3'); strava.athlete.get({},function(err,payload,limits) { if(!err) { console.log(payload); } else { console.log(err); } }); ``` -------------------------------- ### Overriding Access Token per API Call in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This example demonstrates how to explicitly pass an `access_token` as an argument to an individual API call. This method overrides any globally configured access token for that specific request, providing granular control over authentication for single operations. ```javascript const strava = require('strava-v3'); const payload = await strava.athlete.get({'access_token':'abcde'}) ``` -------------------------------- ### Checking Global Strava API Rate Limit Status in Node.js Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet illustrates how to access the global rate limiting status provided by the `strava-v3` wrapper. It shows how to check if the most recent request exceeded the rate limit using `strava.rateLimiting.exceeded()` and how to get the current fraction of the rate limit used via `strava.rateLimiting.fractionReached()`. ```JavaScript // returns true if the most recent request exceeded the rate limit strava.rateLimiting.exceeded() // returns the current decimal fraction (from 0 to 1) of rate used. The greater of the short and long term limits. strava.rateLimiting.fractionReached(); ``` -------------------------------- ### General API Call Structure with Promise API in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet illustrates the general structure for making API calls using the Promise-based interface of `strava-v3`. It shows how to chain API endpoints and options, passing arguments to retrieve data asynchronously. This is the recommended approach for new implementations. ```javascript var strava = require('strava-v3') // Promise API strava..(args) ``` -------------------------------- ### Importing strava-v3 Library in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet demonstrates the standard ES module import syntax to bring the `strava-v3` library into your JavaScript file, assigning it to the `strava` default import. This is suitable when only the main library functionality is needed. ```javascript import strava from 'strava-v3'; ``` -------------------------------- ### Uploading Files to Strava using Node.js Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet demonstrates how to upload a GPX file to Strava using the `strava-v3` Node.js wrapper. It shows how to specify the `data_type` and `file` path, and includes an optional `statusCallback` for monitoring upload progress. The `post` method of `strava.uploads` is used for this operation. ```JavaScript const strava = require('strava-v3'); const payload = await strava.uploads.post({ data_type: 'gpx', file: 'data/your_file.gpx', name: 'Epic times', statusCallback: (err,payload) => { //do something with your payload } }); ``` -------------------------------- ### Importing strava-v3 Library and Interfaces in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet shows how to import both the default `strava` object and specific interfaces, such as `Strava`, from the `strava-v3` library using ES module syntax. This is useful for type-checking or when needing access to the library's defined types. ```javascript import { default as strava, Strava } from 'strava-v3'; ``` -------------------------------- ### Overriding Access Token with New Client Instance in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet shows how to create a new `strava-v3` client instance with a specific `access_token`, allowing API calls on behalf of a particular user. This is useful for multi-user applications where each user has their own token, enabling detailed athlete information and `PUT`/`POST`/`DELETE` privileges. ```javascript const stravaApi = require('strava-v3'); // ... get access_token from somewhere strava = new stravaApi.client(access_token); const payload = await strava.athlete.get({}) ``` -------------------------------- ### Deprecated OAuth Configuration File Structure (JSON) Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This JSON snippet shows the deprecated structure for a `strava_config` file, which was previously used to configure OAuth parameters. While still functional, explicit configuration or environment variables are now the preferred methods for providing these credentials. ```json { "access_token" : "Your apps access token (Required for Quickstart)", "client_id" : "Your apps Client ID (Required for oauth)", "client_secret" : "Your apps Client Secret (Required for oauth)", "redirect_uri" : "Your apps Authorization Redirection URI (Required for oauth)" } ``` -------------------------------- ### General API Call Structure with Callback API in JavaScript (Deprecated) Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet outlines the general structure for making API calls using the deprecated Callback API of `strava-v3`. It demonstrates how to pass arguments and a callback function to handle the API response. The Promise API is preferred for modern JavaScript development. ```javascript var strava = require('strava-v3') // Callback API strava..(args,callback) ``` -------------------------------- ### Explicit OAuth Configuration for strava-v3 in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This code demonstrates how to explicitly configure OAuth parameters for `strava-v3` by passing an object to `strava.config()`. This method overrides any settings from config files or environment variables, providing direct control over authentication credentials. ```javascript var strava = require('strava-v3') strava.config({ "access_token" : "Your apps access token (Required for Quickstart)", "client_id" : "Your apps Client ID (Required for oauth)", "client_secret" : "Your apps Client Secret (Required for oauth)", "redirect_uri" : "Your apps Authorization Redirection URI (Required for oauth)" }); ``` -------------------------------- ### Handling Pagination in strava-v3 API Calls in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet illustrates how to control pagination for API calls that support it, by including `page` and `per_page` properties in the arguments object. This allows fetching specific pages of results and controlling the number of items returned per page. ```javascript const strava = require('strava-v3'); const payload = await strava.athlete.listFollowers({ page: 1, per_page: 2 }); ``` -------------------------------- ### Exchanging Authorization Code for Access Token in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This JavaScript snippet illustrates how to exchange an `authorizationCode` obtained from the Strava OAuth redirection for an `access_token` using the `strava.oauth.getToken` method. The `access_token` is crucial for authenticating subsequent API requests and is found within the `payload.access_token` property of the returned object. This is a crucial step in setting up the test environment. ```JavaScript // access_token is at payload.access_token const payload = await strava.oauth.getToken(authorizationCode) ``` -------------------------------- ### Handling Strava API Errors in JavaScript Source: https://github.com/node-strava/node-strava-v3/blob/main/README.md This snippet demonstrates how to catch `StatusCodeError` and `RequestError` when interacting with the Strava API using the `node-strava-v3` library. It shows both Promise-based error handling using `.catch()` and callback-based error handling, where the error object is passed as the first argument to the callback function. These custom error types provide detailed information for debugging. ```JavaScript const { StatusCodeError, RequestError } = require('./axiosUtility'); // Catch a non-2xx response with the Promise API badClient.athlete.get({}) .catch(StatusCodeError, function (e) { }); badClient.athlete.get({}, function(err, payload) { // err will be an instance of StatusCodeError or RequestError }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.