> For the complete documentation index, see [llms.txt](https://valor-biomechanics.gitbook.io/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valor-biomechanics.gitbook.io/api/reference/api-reference/sessions.md).

# sessions

## Retrieving Sessions within your Organization

## Retrieve recorded movement session(s).

<mark style="color:blue;">`GET`</mark> `https://487q8d7goe.execute-api.us-east-1.amazonaws.com/production/sessions`

Obtains all of the recorded movement sessions (excluding free sessions) or specific sessions within your Valor account based on query parameters.&#x20;

#### Query Parameters

| Name      | Type   | Description                                                                                         |
| --------- | ------ | --------------------------------------------------------------------------------------------------- |
| athleteID | String | Valor ID of a specific athlete to retrieve subset of sessions (can be extracted from athletes call) |
| limit     | String | Limited number of total sessions to return (used for pagination)                                    |

#### Headers

| Name                                                   | Type   | Description                                                                                                                                      |
| ------------------------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Authorization<mark style="color:red;">\*</mark>        | String | <p>JWT Bearer Token for authentication: <br><strong>Bearer \<JWT token></strong></p>                                                             |
| X-Continuation-Token<mark style="color:red;">\*</mark> | String | Continuation token required for paginating requests. Can be found within the response. Default value should be an empty string encoded as a JSON |

{% tabs %}
{% tab title="200: OK Sessions successfully retrieved" %}

```json
{
    "statusCode": 200, 
    "X-Continuation-Token": "{Continuation Token}", //null when all sessions retrieved
    "body": [] //Array of sessions found
}
```

{% endtab %}

{% tab title="404: Not Found No sessions found for the organization" %}

```json
{
    "message": "String type - this will contain more details about the problem encountered"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Endpoint request timed out" %}

```json
{
    "message": "String type - this will contain more details about the problem encountered"
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Note:** When retrieving multiple sessions it is highly recommended to paginate your requests using the limit & X-Continuation-Token parameters. **See examples below:**&#x20;
{% endhint %}

{% tabs %}
{% tab title="Python" %}

```python
import requests
import json

# Define the API endpoint
api_url = 'your_api_url'

# Initialize an empty list to store all items
all_items = []

# Default continuation token should be an emptry string wrapped in a json
continuation_token = json.dumps("")

# Replace 'your_jwt_token' with your actual JWT token
jwt_token = 'your_jwt_token'

while True:
    # Create headers with the X-Continuation-Token and JWT token
    headers = {
        'X-Continuation-Token': continuation_token,  # Include the continuation token
        'Authorization': f'Bearer {jwt_token}'
    }

    # Define query parameters
    params = {
        'limit': '', # Replace with the limit you need (Default = '')
        'athleteID': ''  # Replace with the athlete ID you need (Default = '')
    }

    # Make the API request with the headers and query parameters
    response = requests.get(api_url, headers=headers, params=params)

    if response.status_code == 200:
        data = response.json()
        items = json.loads(data.get('body'))

        # Append the items from the current page to the list
        all_items.extend(items)

        # Check if there's a next page
        continuation_token = data.get('X-Continuation-Token')

        if continuation_token != "null":
            continuation_token = json.dumps(continuation_token)

        if continuation_token == "null":
            # No more pages to fetch, exit the loop
            break
    else:
        print(f"Error: {response.status_code}")
        break
```

{% endtab %}

{% tab title="JavaScript (Node.js)" %}

```javascript
const axios = require('axios');

const jwtToken = 'your_jwt_token_here'; // Replace with your JWT token
let continuationToken = JSON.stringify(''); // Initialize continuation token as empty JSON parameter

const apiUrl = 'your_api_url_here'; // Replace with your API endpoint URL

const allItems = [];

const fetchData = async () => {
  while (true) {
    const headers = {
      Authorization: `Bearer ${jwtToken}`,
      'X-Continuation-Token': continuationToken,
    };
    

    const params = {
        'limit': '', // Replace with the limit you need (Default = '')
        'athleteID': '' // Replace with the athleteID you need (Default = '')
    };

    try {
      const response = await axios.get(apiUrl, { headers, params });
      const data = response.data;
      const items = JSON.parse(data.body);

      allItems.push(...items);

      continuationToken = data['X-Continuation-Token'];

      if (continuationToken !== 'null') {
        continuationToken = JSON.stringify(continuationToken)
      }

      if (continuationToken === 'null') {
        break; // No more pages to fetch
      }
    } catch (error) {
      console.error('Error:', error);
      break;
    }
  }

  // Process allItems as needed
  console.log(allItems.length);
};

fetchData();
```

{% endtab %}

{% tab title="JavaScript (React.js)" %}

```javascript
import React, { useEffect, useState } from 'react';
import axios from 'axios';

const YourComponent = () => {
  const [data, setData] = useState(null);
  const jwtToken = 'your_jwt_token_here'; // Replace with your JWT token
  let continuationToken = JSON.stringify(''); // Initialize continuation token as empty JSON

  const apiUrl = 'your_api_url_here'; // Replace with your API endpoint URL

  useEffect(() => {
    const fetchData = async () => {
      const allItems = [];
      while (true) {
        const headers = {
          Authorization: `Bearer ${jwtToken}`,
          'X-Continuation-Token': continuationToken,
        };
        
        const params = {
          'limit': '', // Replace with the limit you need (Default = '')
          'athleteID': '' // Replace with the athleteID you need (Default = '')
        };

        try {
          const response = await axios.get(apiUrl, { headers, params });
          const data = response.data;
          const items = JSON.parse(data.body);

          allItems.push(...items);

          continuationToken = data['X-Continuation-Token'];
          
          if (continuationToken !== 'null) {
            continuationToken = JSON.stringify(continuationToken);
          }
          
          if (continuationToken === 'null') {
            break; // No more pages to fetch
          }
        } catch (error) {
          console.error('Error:', error);
          break;
        }
      }

      // Process allItems as needed
      setData(allItems);
    };

    fetchData();
  }, []);

  return (
    <div>
      {data ? (
        <pre>{JSON.stringify(data, null, 2)}</pre>
      ) : (
        <p>Loading data...</p>
      )}
    </div>
  );
};

export default YourComponent;
```

{% endtab %}

{% tab title="Native iOS (Swift)" %}

```swift
import Foundation

let jwtToken = "your_jwt_token_here" // Replace with your JWT token
var continuationToken = try JSONSerialization.data(withJSONObject: "") // Initialize continuation token as empty JSON

let apiUrlString = "your_api_url_here" // Replace with your API endpoint URL

var allItems: [Any] = []

while true {
    let apiURL = URL(string: apiUrlString)!
    
    // Define the query parameters as a dictionary
    let queryParameters: [String: String] = [
        "limit": "", // Replace with the limit you need (Default = '')
        "athleteID": "" // Replace with the athleteID you need (Default = '')
    ]
    
    // Create a URLComponents object to handle query parameters
    var components = URLComponents(url: apiUrl, resolvingAgainstBaseURL: false)
    components?.queryItems = queryParameters.map { URLQueryItem(name: $0, value: $1) }

    
    var request = URLRequest(url: components?.url ?? apiURL)
    request.httpMethod = "GET"

    request.setValue("Bearer \(jwtToken)", forHTTPHeaderField: "Authorization")
    request.setValue(continuationToken, forHTTPHeaderField: "X-Continuation-Token")

    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        if let error = error {
            print("Error: \(error)")
        } else if let data = data {
            do {
                let json = try JSONSerialization.jsonObject(with: data, options: [])
                if let dataDict = json as? [String: Any], let items = dataDict["body"] as? [Any] {
                    allItems.append(contentsOf: items)
                    if let newContinuationToken = dataDict["X-Continuation-Token"] as? String {
                        continuationToken = try JSONSerialization.data(withJSONObject: newContinuationToken)
                    } else {
                        continuationToken = "null"
                    }
                }
            } catch {
                print("Error parsing JSON: \(error)")
            }
        }
    }
    task.resume()

    if continuationToken == "null" {
        break // No more pages to fetch
    }
}

// Process allItems as needed
print(allItems)
```

{% endtab %}
{% endtabs %}

## Response (Body) Parameters

1. <mark style="color:green;">**Session ID:**</mark> The unique ID of each session&#x20;
2. <mark style="color:green;">**Date:**</mark> The date the session was recorded (UTC)
3. <mark style="color:green;">**s3Key:**</mark> The s3Key associated with the session. **Note:** This is critical to use to obtain IK or Valor report data.
4. <mark style="color:green;">**Duration:**</mark> The duration of the session in seconds
5. <mark style="color:green;">**Athlete ID:**</mark> The unique athlete ID of each session&#x20;
6. <mark style="color:green;">**Assessment ID:**</mark> The unique assessment ID of each session (shared with sessions recorded under the same assessment) or labeled as "singleExercise" if the session was a stand alone recording
7. <mark style="color:green;">**Exercise ID:**</mark> The unique exercise ID of each session&#x20;
8. <mark style="color:green;">**Session Name:**</mark> The name of the session (usually the name of an exercise)
