FittyAI Workout API Guide

In this documentation, we will guide you through the process of creating and deleting workouts using the FittyAI Workout API.

Prerequisites

  • Python installed on your machine.
  • The requests library. You can install it via pip:
    pip install requests
    

Managing Video and Audio Files for Exercises

For a seamless user experience, it’s vital to offer visual and auditory aids to demonstrate how exercises should be performed. We provide two options to manage your media content:

  1. Custom Storage: Host your video and audio files in your own storage solution, ensuring that these files are publicly accessible to users.

  2. FittyAI Storage: Utilize our secure storage system through our API. This method ensures efficient delivery and seamless integration with our platform. For detailed instructions on using our storage system, please refer to our Upload File Documentation.

Whichever option you choose, ensure that the content provides clear, high-quality demonstrations for users to achieve the best workout results.

Creating a Workout

  1. Setup the API Endpoint and Authorization Token

    Replace placeholders in the following script:

    • Replace YourCompanyName with your company name.
    • Replace YOUR_SECRET_TOKEN with your secret token.
  2. Define the Workout Data

    The workout_data dictionary in the script contains a basic structure for a workout. You can adjust this to include different types of workout flows, like tutorials, exercises, breaks, etc.

  3. Make the POST Request

    The script will send a POST request to the API to create a new workout.

  4. Check the Response

    The script will display the API’s response which will also contain created workout id. A successful creation should return a status code of 200.

Here’s the script for creating a workout:

import requests
import json

BASE_URL = "https://38en04sov6.execute-api.us-west-2.amazonaws.com/v1"
COMPANY_NAME = "YourCompanyName"
ENDPOINT = f"{BASE_URL}/{COMPANY_NAME}/workouts"
SECRET_TOKEN = "YOUR_SECRET_TOKEN"

workout_data = {
    "name": "Simple Workout",
    "displaySummaryScreen": True,
    "useSound": True,
    "workoutFlow": [
        {
            "type": "cameraSetupValidation",
            "duration": 3, #Recomended
            "audioUrl": "https://firebasestorage.googleapis.com/v0/b/fitty-1.appspot.com/o/flamelink%2Fmedia%2Fmake_sure_to_fit_in_the_screen_and_wait_for_3_seconds.mp3",
            "showCameraSetupValidation": True
        },
        {
            "type": "exercise",
            "duration": 30,
            "apiName": "squat",
            "name": "Ordinary Squats",
            "reps": 10,
            "videoUrl": "https://fitty-client-uploads-prod.s3.us-west-2.amazonaws.com/fitty/videos/fitty_video_man_squat_front.webm"
        }
    ]
}

headers = {
    "Authorization": f"Bearer {SECRET_TOKEN}",
    "Content-Type": "application/json"
}

response = requests.post(ENDPOINT, data=json.dumps(workout_data), headers=headers)

if response.status_code == 200:
    print("Workout successfully created!")
    print(response.json())
else:
    print(f"Failed to create workout. Status code: {response.status_code}")
    print(response.text)

Note: Ensure you replace placeholders with appropriate values before running the scripts.

Getting all workouts

Here’s the script for receiving all workouts:


import requests

# API base URL and endpoint
BASE_URL = "https://38en04sov6.execute-api.us-west-2.amazonaws.com/v1"  # Replace 'example.com' with your actual API base URL
COMPANY_NAME = "YourCompanyName"
SECRET_TOKEN = "YOUR_SECRET_TOKEN"
ENDPOINT = f"{BASE_URL}/{COMPANY_NAME}/workouts"

# Set headers
headers = {
    "Authorization": f"Bearer {SECRET_TOKEN}"
}

# Make the GET request to retrieve all workouts
response = requests.get(ENDPOINT, headers=headers)

# Print the response
if response.status_code == 200:
    workouts = response.json()
    for workout in json.loads(workouts["workouts"]):
        print(workout)
else:
    print(f"Failed to retrieve workouts. Status code: {response.status_code}")
    print(response.text)


Note: Ensure you replace placeholders with appropriate values before running the scripts.

Get a workout and all information inside

import requests

# API base URL and endpoint
BASE_URL = "https://38en04sov6.execute-api.us-west-2.amazonaws.com/v1"  # Replace 'example.com' with your actual API base URL
COMPANY_NAME = "YourCompanyName"  # Replace with your company name
WORKOUT_ID = "YOUR WORKOUT ID"
ENDPOINT = f"{BASE_URL}/{COMPANY_NAME}/workouts/{WORKOUT_ID}"

# Secret token for authorization
SECRET_TOKEN = "YOUR_SECRET_TOKEN"  # Replace with your actual secret token

# Set headers
headers = {
    "Authorization": f"Bearer {SECRET_TOKEN}"
}

# Make the GET request to retrieve all workouts
response = requests.get(ENDPOINT, headers=headers)

# Print the response
if response.status_code == 200:
    response = response.json()
    print(json.loads(response['workout']))
else:
    print(f"Failed to retrieve workouts. Status code: {response.status_code}")
    print(response.text)


Note: Ensure you replace placeholders with appropriate values before running the scripts.

Deleting a Workout

Here’s the script for deleting a workout:

import requests

BASE_URL = "https://38en04sov6.execute-api.us-west-2.amazonaws.com/v1"
COMPANY_NAME = "YourCompanyName"
SECRET_TOKEN = "YOUR_SECRET_TOKEN"
ENDPOINT = f"{BASE_URL}/{COMPANY_NAME}/workouts/{WORKOUT_ID}"

headers = {
    "Authorization": f"Bearer {SECRET_TOKEN}"
}

response = requests.delete(ENDPOINT, headers=headers)

if response.status_code == 200:
    print("Workout successfully deleted!")
    print(response.json())
else:
    print(f"Failed to delete workout. Status code: {response.status_code}")
    print(response.text)

Note: Ensure you replace placeholders with appropriate values before running the scripts.