---
title: "Getting Started With hawkinR"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting Started With hawkinR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
dependencies:
  - knitr
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(knitr)
```

## Initializing Your Session

Our API uses bearer token authentication. This form of authentication is executed by providing your unique API Integration Key in a token request to your server. Which then the server will provide you with an access token in it's response.

This process is what is executed within the `get_access` function of the package. We use this function to initialize our session and use all of the other functions of the hawkinR package. By using `get_access` and providing the necessary parameters, your access token will be stored in your session and accessible to any subsequent calls.

```{r getAccess, eval=FALSE}
# use get_access to intialize session
get_access( refreshToken = "your_integration_key", region = "your_region")

"[1] Success! Your access token was recieved and stored for use by other hawkinR functions. Your token will expire at 2023-11-09 09:44:25"
```

If you need more information how to create an API Integration Key, you can check out our article on [How to create an API token](https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Flearning.hawkindynamics.com%2Fknowledge%2Fhow-to-create-an-api-token&data=05%7C01%7Clauren%40hawkindynamics.com%7C85073978788f4b466cb808dbdfd5ae0c%7C4d7400c0ac5b4aa08f8ac3ebebeaefc7%7C0%7C0%7C638349881078418843%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=S%2BO%2FLsWLJ6HZDxxI5ydCAXzf21m%2BMTvCB8gx%2BXNRMzg%3D&reserved=0 "How to create an API token"). Which has details on how to do this on your cloud site.

some user may feel they are in a situation where you can securely store your integration key on your device locally. You will be interested in our other article [How to Store Your API Key](vignettes/Store_API_Key_Locally.html).

> Please note, only the Org Administrator (the account with the highest level of access) is able to create API tokens.  Please contact techsupport\@hawkindynamics.com if you are unsure of your organization's administrator.

## Making Your First Calls

If this is your first time accessing your data through the API, or know you have had changes in your organization since your last session, a good place to start is by calling in your organizational data such as players, teams, and groups. While this information isn't required to call in your test data, it can allow you to be more specific in your queries and save server processing and loading time when calling in test data.

The package was built to allow you the ability to make requests as specific as you need, and in as few lines of code as possible. To execute this, you will need this organizational information to input the parameters needed for that specificity. Each of these calls can be done in 1 line of code and one function. Each function returns a data frame that can be stored in an R object and used as necessary.

In this example, I will store athlete information in an object called 'roster', team information in an object called 'teams', and group information in an object named 'groups'.

### Get Athletes:

Returns a data frame with variables of: id, name, active, teams, groups, and external. If an athlete has external fields assigned to them, the string will contain the external name and external ID separated by a colon. And multiple externals will be separated by a comma.

```{r roster, eval=FALSE}
# store player info in object called roster. 'inactive' is default to FALSE. Set to TRUE if you want to include inactive athletes.
roster <- get_athletes(inactive = FALSE)
```

```{r rosterResp, echo=FALSE}
roster <- data.frame(
  "id" = c("0kEjAzSLpBwUZc4Yp2Ov", "1E1zYBv0CKbrKnsKz1vj", "1lXEZKkNuNwvMLXiqFRr"),
  "name" = c("Athlete One", "Player Two", "Person Three"),
  "active" = c(TRUE, TRUE, TRUE),
  "teams" = c("09u20ij0dj0", "09u20ij0dj0", "9308dj209dj"),
  "groups" = c("0j20j09jd9ud0j", "0j20j09jd9ud0j,92d2098d02j0", ""),
  "external" = c("AMS:dj0203j0dj,GPS:md029j3209j2","AMS:oin208ju09,GPS:od093j32", "AMS:j029j0jd20j,GPS:0d28j098h3")
)

kable(roster)
```

### Get Teams:

Returns a data frame with variables: id and name.

```{r teams, eval=FALSE}
# store team info in an object called teams.
teams <- get_teams()
```

```{r teamsResp, echo=FALSE}
teams <- data.frame(
  "id" = c("09u20ij0dj0", "9308dj209dj"),
  "name" = c("Team One", "Team Two")
)

kable(teams)
```

### Get Groups:

Returns a data frame with variables: id and name.

```{r groups, eval=FALSE}
# store group info in an object called groups.
groups <- get_groups()
```

```{r groupsResp, echo=FALSE}
groups <- data.frame(
  "id" = c("0j20j09jd9ud0j", "92d2098d02j0"),
  "name" = c("Position Group", "Grad Year Group")
)

kable(groups)
```

## Test Types

Lastly, there are 9 different test collection modes in our software. And thus, we have 9 different test type IDs. These test IDs are what will be used in `get_tests_type` function, NOT the test name. So it is a good idea to store the test types as an object as well. This also has a single function to execute, which returns a data frame with the test type name and ID.

```{r types, eval=FALSE}
# store test type IDs in an object called testIds
testIds <- get_testTypes()
```

```{r typesResp, echo=FALSE}
tests <- data.frame(
  "name" = c("Countermovement Jump","	
Squat Jump","	
Isometric Test", "Drop Jump", "Free Run", "CMJ Rebound", "Multi Rebound", "Weigh In", "Drop Landing"),
"id" = c("7nNduHeM5zETPjHxvm7s","QEG7m7DhYsD6BrcQ8pic", "2uS5XD5kXmWgIZ5HhQ3A", "gyBETpRXpdr63Ab2E0V8", "5pRSUQVSJVnxijpPMck3", "pqgf2TPUOQOQs6r0HQWb", "r4fhrkPdYlLxYQxEeM78", "ubeWMPN1lJFbuQbAM97s", "rKgI4y3ItTAzUekTUpvR")
)

kable(tests)

```

------------------------------------------------------------------------

With these objects, you can access any of the IDs and information you would need for your test queries. See the other vignettes [How to Get Tests](vignettes/Get_Tests.html) and [Accessing Force-Time Data of A Test](vignettes/Get_ForceTime_Data.html) for specific details on ways to execute those queries.
