Interface to the 'Hawkin Dynamics' Force Platform API

Provides a secure and configurable interface to the 'Hawkin Dynamics' API for accessing athlete performance data, tests, and metadata. The package supports profile-based authentication with secure credential storage via the operating system keychain, automatic access token refresh, and region-aware API routing. Designed for reproducible analysis, data synchronization workflows, and production deployment.


hawkinR hawkinR website

Get your data from the Hawkin Dynamics API

R-CMD-check Last-changedate license minimal Rversion Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. lifecycle packageversion

hawkinR provides simple functionality with Hawkin Dynamics API. These functions are for use with ‘Hawkin Dynamics Beta API’ version 1.10-beta. You must be an Hawkin Dynamics user with active integration account to utilize functions within the package.

Installation

Install the released version of hawkinR from CRAN:

install.packages("hawkinR")

Or install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("HawkinDynamics/hawkinR")

Functions

This API is designed to get data out of your Hawkin Dynamics database into your own database. It is not designed to be accessed from client applications directly. There is a limit on the amount of data that can be returned in a single request. As your database grows, it will be necessary to use the from and to parameters to limit the size of the responses. Responses that exceed the memory limit will fail. It is advised that you design your client to handle this from the beginning. A recommended pattern would be to have two methods of fetching data. A scheduled pull that uses the from and to parameters to constrain the returned data to only tests that have occurred since the last fetch e.g. every day or every 5 minutes. And then a pull that fetches the entire database since you began testing that is only executed when necessary. A recommended way of doing this is to generate the from and to parameters for each month since you started and send a request for each either in parallel or sequentially.

This package was meant to help execute requests to the Hawkin Dynamics API with a single line of code. There are 11 functions to help execute 4 primary objectives:


Authentication

hawkinR uses a secure, profile-based authentication system designed for both local development and production deployment.

Key concepts
  • Profiles
    • A profile is a named credential slot (for example, a development token, a production token, or a team-specific token). Your Refresh Token is stored under the profile name in the OS keychain.
    • Organization (org_id) and region are supplied per session when you call hd_connect().
  • Secrets
    • API tokens are never stored in plain text.
      • Local development: stored securely using the operating system keychain via the keyring package
      • Production deployments: injected via environment variables
  • Automatic token refresh
    • Access tokens are refreshed automatically when needed. Users do not need to manage token expiration.
Local development (recommended)
  1. Store your Integration Key (Refresh Token) securely in the OS keychain. This opens a secure prompt and saves the token via the keyring package under the given profile:
hd_auth_store()                      # stores under the "default" profile
# hd_auth_store(profile = "research")  # or store a named profile
  1. Connect. hd_connect() reads the stored key, exchanges it for an access token, and sets the active session used by every get_*() call:
hd_connect(region = "Americas")      # environment = "development" (default)

All subsequent API calls authenticate automatically; access tokens are refreshed as needed.

Production deployments (Shiny, Plumber, CI/CD)

In hosted environments the OS keychain is unavailable, so authenticate from an environment variable instead. When environment = "production", hawkinR reads the Refresh Token from HAWKIN_KEY_<PROFILE> — the profile name, upper-cased. The default profile reads HAWKIN_KEY_DEFAULT.

# The hosting platform sets the environment variable (never commit the token):
#   HAWKIN_KEY_DEFAULT = <your Refresh Token>

hd_connect(environment = "production", region = "Americas")

No secrets are written to disk.

Regions

hd_connect(region = ...) accepts "Americas" (default), "Europe", or "APAC".

Resetting credentials

Remove a stored Refresh Token from the keychain:

hd_auth_reset()                      # removes the "default" profile
# hd_auth_reset(profile = "research")

Get Test Types

  • get_testTypes() - Get the test type names and ids for all the test types in the system. Response will be a data frame containing the tests that are in the HD system.

Get Organization Data

  • get_athletes() - Get the athletes for an account. Inactive players will only be included if `inactive` parameter is set to TRUE. Response will be a data frame containing the athletes that match this query.

  • get_teams() - Get the team names and ids for all the teams in the org. Response will be a data frame containing the teams that are in the organization.

  • get_groups() - Get the group names and ids for all the groups in the org. Response will be a data frame containing the groups that are in the organization.

Get Test Data

  • get_forcetime() - Get the force-time data for a specific test by id. This includes both left, right and combined force data at 1000hz (per millisecond). Calculated velocity, displacement, and power at each time interval will also be included.

  • get_tests() - Get the tests for an account. You can specify none or any 1 of the parameters athlete, test type, teams or groups; as well as a time frame from, or to, which the tests should come (or be synced). Response will be a data frame containing the trials within the time range (if specified).

Note: the legacy get_tests_type, get_tests_ath, get_tests_team, and get_tests_group helpers were deprecated in hawkinR v1.x and removed in v2.0.0. Use get_tests() with the corresponding typeId, athleteId, teamId, or groupId argument instead.

Example

This is a basic example which shows common workflow:

library(hawkinR) 


#------------------------------------------------------------------------------------#
# 1. Get access to your site
#------------------------------------------------------------------------------------#


## Store you secret API key
refreshToken <- 'your-secret-api-key'

## Get access token. When successful, access token is stored for use in the session.
get_access("refreshToken", region = "Americas")


#------------------------------------------------------------------------------------#
# 2. Get Org data
#------------------------------------------------------------------------------------#

## Team data frame
teamList <- get_teams()

## Create list of teams
teamIds <- paste0(teamList$id[1],teamList$id[3],teamList$id[4])

## Athlete data frame
athList <- get_athletes()

## Create athleteId
athId <- athList$id[6]

#------------------------------------------------------------------------------------#
# 3. Get Test Data
#------------------------------------------------------------------------------------#

## Initial test call
allTests <- get_tests()

## Create last test or sync date
lastSync <- max(allTests$lastSyncTime)

## Create phase to review with timestamp from records
phaseDate1 <- allTests$timestamp[30] # from dateTime
phaseDate2 <- allTests$timestamp[10] # to dateTime

## Dates can also be entered as character strings in "YYYY-MM-DD" format
phaseDate1_string <- "2024-01-01"
phaseDate2_string <- "2024-06-01"

## Sync tests since a time point.
df_SyncFrom <- get_tests(from = lastSync, sync = TRUE)

## Get tests by athlete in time frame.
df_athTests <- get_tests(athleteId = athId, from = phaseDate1, to = phaseDate2)

## Get all tests by team
df_teamTests <- get_tests(teamId = teamIds)

## Get test force-time data
df_forceData <- get_forcetime(testId = df_athTests$id[10])

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.