How To: Getting Started With Reboot Motion's API

This tutorial uses code samples written in Python; however, if your organization uses a different language, you can still use the tutorials as a reference point — you will just need to translate the examples to the language of your choosing.

Welcome! If you're new to coding or new to Reboot Motion, you may need some assistance with getting set up so you can properly access the Reboot Motion API. Below you will find some common elements you will see across our tutorials and within our API documentation. If we are missing anything, please let us know at [email protected].

Import Statements

Import statements allow us to leverage code from external Python modules and avoid writing repetitive code. If you're interested in learning more about importing Python packages and modules, you can read more about those here.

Below are some of the most common import statements seen in the Reboot Motion API tutorials:

import os

The os module in Python allows the user to interact with the native OS that Python is running on, allowing the user to interact with multiple different Python libraries and functions that are not native to Python itself. This is a great way to use third-party libraries to keep from doing duplicate work. The os module is a module that is provided by Python itself and not a third-party library; that means that you will not need to pip install os in order to use it.

import requests

We also import the requests module (and install it with pip install requests), which is how we are able to send HTTP requests using Python, an essential step to making calls to the Reboot Motion API. We are using the requests module, but there are multiple modules you can use for making HTTP requests in Python and other languages; requests is just the library we’ve chosen to use at Reboot Motion. If your organization uses another library for sending HTTP requests, the functionality will be the same as the requests module and you will want to use that library instead.

If you've never used the requests library before, you can check out the official Python documentation or you can go through this helpful tutorial found on Real Python that walks you through the basics of using the requests library.

import pandas as pd

There are multiple ways to consume and filter CSV files, so you are free to use whichever method you are most comfortable with; but for us, that’s Pandas. Pandas is a third-party library, and must be installed by running pip install pandas. You can find the Pandas documentation here to go more in-depth. Lastly, we import pandas with the alias of pd because that is the industry standard and makes it cleaner and easier to read in the code.

Constants

It’s very easy (and possible) to go through the Reboot Motion tutorials by typing every piece of code out manually and completely, but that can be time consuming and tedious, and allows for a lot of room for error. We recommend using constants that can be reused throughout the code in our tutorial files, allowing you to have more readable code and only have to change the value of a constant in one place instead of multiple. Any constants used in the Reboot Motion tutorials will be defined within the tutorial itself, as they vary.

One caveat to the constants used throughout our tutorials is that they are typically example values. This means you cannot plug and play with the majority of the example values as they currently are; you will need to use the specific values for your organization/player/etc. The example values provided are for a fictional example player.

API Key

In the Reboot Motion tutorials, we will be accessing the API Key from the environment as an environment variable. There are multiple ways to do this; at Reboot Motion, we prefer to use a .env file housed in the root directory of the project. Whichever method you use to store your API Key, you will need to make sure that you are using the correct environment variable name when you make your request and you will want to keep whatever file houses your API Key off of any public GitHub repositories to prevent anyone from gaining access to your organization’s data without your explicit knowledge or consent.

Making a Request to the Reboot Motion API

In order to interact with the Reboot Motion API, you will need to make a request; this will typically either be a GET request or a POST request. You can also make a PATCH or DELETE request, but those are less frequently used. Let's go through what each request type means, before getting to an example:

A GET request is used to retrieve data from the Reboot Motion API. A good example of this is getting a list of players from your organization's roster.

A POST request is used to create a resource by sending data to the Reboot Motion API. A good example of this is creating a new player in your organization's roster.

A PATCH requests is used to update a resource. You would use a PATCH request to update only a portion of the resource (i.e. a player's height).

We do not have many DELETE requests available in the Reboot Motion API, but a DELETE request is used to delete a resource.

Now that we've familiarized ourselves with the possible requests you can send, let's walk through an example showing how to properly make a POST request in your code. These steps will be largely applicable for a GET, PATCH, and DELETE request as well with some minor modifications, which will all be detailed in the Reboot Motion API Documentation.

This example demonstrates how to create a player in your organization with the name John Smith, born on March 30, 1993, who is 6 feet tall, weighs 200 pounds, and hits and throws right-handed.

import requests

API_HEADER = {'x-api-key': <YOUR-REBOOT-API-KEY>}

new_player = requests.post(
    "https://api.rebootmotion.com/player",
    headers=API_HEADER,
    json={
        "first_name": "John",
        "last_name": "Smith",
        "date_of_birth": ""1993-03-30",
        "attributes": {
            "dom_hand_hitting": "RHA",
            "dom_hand_throwing": "RHA",
            "height_ft": 6.0,
            "weight_lbs": 200
        }
    }
)

Following this structure will allow you to make any basic HTTP request to the Reboot Motion API. If you are looking to make a more complex request, you can find more information in the Reboot Motion API Documentation or the Reboot Motion Tutorials.