Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Sports

GET /api/sports

  Get all sports

  Scope: `workouts:read`

  Example request:

      GET /api/sports HTTP/1.1
      Content-Type: application/json

  Example response:

  - for non admin user:

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
        "data": {
          "sports": [
            {
              "color": null,
              "id": 1,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Sport)",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "id": 2,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Transport)",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "id": 3,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Hiking",
              "stopped_speed_threshold": 0.1
            },
            {
              "color": null,
              "id": 4,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Mountain Biking",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "id": 5,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Running",
              "stopped_speed_threshold": 0.1
            },
            {
              "color": null,
              "id": 6,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Walking",
              "stopped_speed_threshold": 0.1
            }
          ]
        },
        "status": "success"
      }

  - for admin user:

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
        "data": {
          "sports": [
            {
              "color": null,
              "has_workouts": true,
              "id": 1,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Sport)",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "has_workouts": false,
              "id": 2,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Transport)",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "has_workouts": false,
              "id": 3,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Hiking",
              "stopped_speed_threshold": 0.1
            },
            {
              "color": null,
              "has_workouts": false,
              "id": 4,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Mountain Biking",
              "stopped_speed_threshold": 1
            },
            {
              "color": null,
              "has_workouts": false,
              "id": 5,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Running",
              "stopped_speed_threshold": 0.1
            },
            {
              "color": null,
              "has_workouts": false,
              "id": 6,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Walking",
              "stopped_speed_threshold": 0.1
            }
          ]
        },
        "status": "success"
      }

  Request Headers:

    - Authorization – OAuth 2.0 Bearer Token

  Status Codes:

    - 200 OK – `success`

    - 401 Unauthorized –

      - `provide a valid auth token`

      - `signature expired, please log in again`

      - `invalid token, please log in again`

GET /api/sports/(int: sport_id)

  Get a sport

  Scope: `workouts:read`

  Example request:

      GET /api/sports/1 HTTP/1.1
      Content-Type: application/json

  Example response:

  - success for non admin user:

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
        "data": {
          "sports": [
            {
              "color": null,
              "id": 1,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Sport)",
              "stopped_speed_threshold": 1
            }
          ]
        },
        "status": "success"
      }

  - success for admin user:

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
        "data": {
          "sports": [
            {
              "color": null,
              "has_workouts": false,
              "id": 1,
              "is_active": true,
              "is_active_for_user": true,
              "label": "Cycling (Sport)",
              "stopped_speed_threshold": 1
            }
          ]
        },
        "status": "success"
      }

  - sport not found:

      HTTP/1.1 404 NOT FOUND
      Content-Type: application/json

      {
        "data": {
          "sports": []
        },
        "status": "not found"
      }

  Parameters:

    - sport_id (integer) – sport id

  Request Headers:

    - Authorization – OAuth 2.0 Bearer Token

  Status Codes:

    - 200 OK – `success`

    - 401 Unauthorized –

      - `provide a valid auth token`

      - `signature expired, please log in again`

      - `invalid token, please log in again`

    - 404 Not Found – `sport not found`

PATCH /api/sports/(int: sport_id)

  Update a sport.

  Authenticated user must be an admin.

  Scope: `workouts:write`

  Example request:

      PATCH /api/sports/1 HTTP/1.1
      Content-Type: application/json

  Example responses:

  - success:

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
        "data": {
          "sports": [
            {
              "color": null,
              "has_workouts": false,
              "id": 1,
              "is_active": false,
              "is_active_for_user": false,
              "label": "Cycling (Sport)",
              "stopped_speed_threshold": 1
            }
          ]
        },
        "status": "success"
      }

  - sport not found:

      HTTP/1.1 404 NOT FOUND
      Content-Type: application/json

      {
        "data": {
          "sports": []
        },
        "status": "not found"
      }

  Parameters:

    - sport_id (integer) – sport id

  Request JSON Object:

    - is_active (string) – sport active status

  Request Headers:

    - Authorization – OAuth 2.0 Bearer Token

  Status Codes:

    - 200 OK – sport updated

    - 400 Bad Request – `invalid payload`

    - 401 Unauthorized –

      - `provide a valid auth token`

      - `signature expired, please log in again`

      - `invalid token, please log in again`

    - 403 Forbidden – `you do not have permissions`

    - 404 Not Found – `sport not found`

    - 500 Internal Server Error – `error, please try again or contact the administrator`