Automate Strava Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access Strava data from PowerShell? This article demonstrates how to utilize the Strava Cmdlets for tasks like connecting to Strava data, automating operations, downloading data, and more.

The CData API Driver for ADO.NET is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Strava.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Strava; this tutorial shows how to use the Provider to retrieve Strava data.

Once you have acquired the necessary connection properties, accessing Strava data in PowerShell can be enabled in three steps.

To authenticate to Strava, and connect to your own data or to allow other users to connect to their data, you can use the OAuth standard.

Using OAuth Authentication

You must create a custom OAuth application to connect to Strava. To create a custom OAuth application:

  1. Log into the Strava API Settings page
  2. Create a new application or select an existing application
  3. Set the "Authorization Callback Domain" to your callback URL domain (e.g. localhost)
  4. Note down the Client ID and Client Secret

After setting the following connection properties, you are ready to connect:

  • AuthScheme: Set this to OAuth.
  • InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to manage the process to obtain the OAuthAccessToken.
  • OAuthClientId: Set this to the Client ID from your Strava API application.
  • OAuthClientSecret: Set this to the Client Secret from your Strava API application.
  • CallbackURL: Set this to the redirect URI matching your application's callback domain.

Example connection string:

Profile=C:\profiles\Strava.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=http://localhost:33333;
  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData API Driver for ADO.NET\lib\System.Data.CData.API.dll")
        
  2. Connect to Strava:

     
    $conn= New-Object System.Data.CData.API.APIConnection("Profile=C:\profiles\Strava.apip;AuthScheme=OAuth;InitiateOAuth=GETANDREFRESH;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=http://localhost:33333;")
    $conn.Open()
    
  3. Instantiate the APIDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ,  from Athlete"
    
    $da= New-Object System.Data.CData.API.APIDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_. $_.
    }
      

Ready to get started?

Connect to live data from Strava with the API Driver

Connect to Strava