Prerequisites
- Node.js installed on your machine
- A Strava Developer account
- A Notion account
Step 1 - Get Your API Keys
Strava API Key1
Log in to your Strava account.
2
Go to Strava API.
3
Click on Create An App.
4
Fill in the required details and click Create.
5
Copy the Client ID and Client Secret.
1
Log in to your Notion account.
2
Go to Notion Connections.
3
Click on New Connection.
4
Fill in the required details and click Submit.
5
Copy the generated Installation access token.
Step 2 - Set Up Your Notion Database
1
Create a new database in Notion with the following properties:
- Name (Title)
- Distance (Number)
- Pace (Text)
- Duration (Text)
- Elevation Gain (Number)
- Type (Text)
- Date (Date)
- Calories (Number)
2
Share the database with your connection:
- Click on the three dots in the top-right corner of the page.
- Under Connections, click on Connect to and search for your connection and invite it.
Step 3 - Project Structure
This step is not necessary but we suggest projects to be structured like so:Step 4 - Create .env file
Create a.env file in your project directory with the following with the following information:
YAML
Please note that you will have to update your
.env file with your STRAVA_ACCESS_TOKEN and STRAVA_REFRESH_TOKEN after completing Strava’s OAuth flow.Step 5 - Packages
Install the required Node.js packages using the following command:package.json file and add the following:
JSON
Step 6 - OAuth Flow
Createserver.js to handle the OAuth flow:
JavaScript
Step 7 - Set Up Strava API Client
Createstrava.js to set up the Strava API client:
JavaScript
Step 8 - Set Up Notion API Client
Create anotion.js file to set up the Notion API client using the @notionhq/client library. Use your Notion installation access token and database ID.
JavaScript
Step 9 - Fetch Activity Data From Strava
Create astravaIntegration.js file to fetch activity data from your Strava account:
JavaScript
Step 10 - Populate Notion Database with Strava Activity Data
Create anotionIntegration.js file to handle populating the Notion database with all Strava activities.
JavaScript
Step 11 - Main Script
Create amain.js file that uses the modules created above to execute the connection logic.
JavaScript
Step 12 - Run the OAuth Flow
1
Start the OAuth Server:
2
Open your browser and navigate to
http://localhost:3000:- You should see a page with a link to authorize with Strava.
3
Click the link to authorize with Strava:
- This will redirect you to Strava’s authorization page.
4
Authorize the application:
- Strava will redirect you to a page with an authorization code.
5
The server will exchange the authorization code for an access token and refresh token:
- The tokens will be displayed on the page.
6
Copy the refresh token and update your
.env file with it.