Excel Spreadsheet Automation on Strava Data with the QUERY Formula
The CData Excel Add-In for Strava provides formulas that can query Strava data. The following three steps show how you can automate the following task: Search Strava data for a user-specified value and then organize the results into an Excel spreadsheet.
The syntax of the CDATAQUERY formula is the following:
=CDATAQUERY(Query, [Connection], [Parameters], [ResultLocation]);
This formula requires three inputs:
- Query: The declaration of the Strava data records you want to retrieve, written in standard SQL.
Connection: Either the connection name, such as APIConnection1, or a connection string. The connection string consists of the required properties for connecting to Strava data, separated by semicolons.
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:
- Log into the Strava API Settings page
- Create a new application or select an existing application
- Set the "Authorization Callback Domain" to your callback URL domain (e.g. localhost)
- 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;
- ResultLocation: The cell that the output of results should start from.
Pass Spreadsheet Cells as Inputs to the Query
The procedure below results in a spreadsheet that organizes all the formula inputs in the first column.
- Define cells for the formula inputs. In addition to the connection inputs, add another input to define a criterion for a filter to be used to search Strava data, such as .
- In another cell, write the formula, referencing the cell values from the user input cells defined above. Single quotes are used to enclose values such as addresses that may contain spaces.
- Change the filter to change the data.
=CDATAQUERY("SELECT * FROM Athlete WHERE = '"&B7&"'","Profile="&B1&";AuthScheme="&B2&";InitiateOAuth="&B3&";OAuthClientId="&B4&";OAuthClientSecret="&B5&";CallbackURL="&B6&";Provider=API",B8)