# On-demand

> Your workout studios, recipe books and resource collections, and which clients can open them.

Source: https://hubfit.com/developers/api/on-demand


What a coach puts up for clients to use any time, in three kinds that work alike, each up to 100 per workspace. Workout studios hold workouts, recipe books hold recipes, and resource collections hold resources. A client sees one in their app once you grant them access.

Endpoints:

- `GET /v1/workout-studios`: [List workout studios](https://hubfit.com/developers/api/on-demand#list-workout-studios)
- `POST /v1/clients/{clientId}/workout-studios`: [Grant a client access to a workout studio](https://hubfit.com/developers/api/on-demand#grant-client-workout-studio-access)
- `DELETE /v1/clients/{clientId}/workout-studios/{workoutStudioId}`: [Revoke a client's access to a workout studio](https://hubfit.com/developers/api/on-demand#revoke-client-workout-studio-access)
- `GET /v1/recipe-books`: [List recipe books](https://hubfit.com/developers/api/on-demand#list-recipe-books)
- `POST /v1/clients/{clientId}/recipe-books`: [Grant a client access to a recipe book](https://hubfit.com/developers/api/on-demand#grant-client-recipe-book-access)
- `DELETE /v1/clients/{clientId}/recipe-books/{recipeBookId}`: [Revoke a client's access to a recipe book](https://hubfit.com/developers/api/on-demand#revoke-client-recipe-book-access)
- `GET /v1/resource-collections`: [List resource collections](https://hubfit.com/developers/api/on-demand#list-resource-collections)
- `POST /v1/clients/{clientId}/resource-collections`: [Grant a client access to a resource collection](https://hubfit.com/developers/api/on-demand#grant-client-resource-collection-access)
- `DELETE /v1/clients/{clientId}/resource-collections/{resourceCollectionId}`: [Revoke a client's access to a resource collection](https://hubfit.com/developers/api/on-demand#revoke-client-resource-collection-access)

## Workout studio object

### Attributes

- `id` (string): Its unique ID.
- `name` (string)

### Example

```json
{
  "id": "6ad6af358bfd50368bfee337",
  "name": "Home workouts"
}
```

## Recipe book object

### Attributes

- `id` (string): Its unique ID.
- `name` (string)

### Example

```json
{
  "id": "6ad6af48098ec0490990534a",
  "name": "High-protein meals"
}
```

## Resource collection object

### Attributes

- `id` (string): Its unique ID.
- `name` (string)

### Example

```json
{
  "id": "6ad6af06142ae30514295008",
  "name": "Getting started"
}
```

## List workout studios

`GET https://api.hubfit.com/v1/workout-studios`

Every workout studio in the workspace, newest first, to pass one's `id` when granting a client access. A workspace has no more than 100, so they all come in one response, without paging. Requires `on-demand:write`.

### Returns

Every workout studio in the workspace.

### Example request

cURL:

```bash
curl https://api.hubfit.com/v1/workout-studios \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/workout-studios", {
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.get(
    "https://api.hubfit.com/v1/workout-studios",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": [
    {
      "id": "6ad6af358bfd50368bfee337",
      "name": "Home workouts"
    }
  ]
}
```

## Grant a client access to a workout studio

`POST https://api.hubfit.com/v1/clients/{clientId}/workout-studios`

Grants the client access to the workout studio, as adding them under Manage Access in the app does: it shows in their app and they get a notification. Workout Studio appears in their app if it wasn't there. If they already have access, nothing changes and nothing is sent: that's a `200` instead of a `201`, so a retry is safe. Requires `on-demand:write`.

### Headers

- `Idempotency-Key` (string): Any unique string, such as a UUID, up to 255 characters. Retrying with the same key within 24 hours returns the first response instead of repeating the write. See [Idempotency](https://hubfit.com/developers/idempotency).

### Path parameters

- `clientId` (string, required): The client's `id`.

### Body parameters

- `workoutStudioId` (string, required)

### Returns

`200`: The client already had access, so nothing changed. `201`: Access granted.

### Example request

cURL:

```bash
curl -X POST https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios \
  -H "Authorization: Bearer $HUBFIT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "workoutStudioId": "6ad6af358bfd50368bfee337"
  }'
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    workoutStudioId: "6ad6af358bfd50368bfee337",
  }),
});

const { data } = await response.json();
```

Python:

```python
import os
import uuid
import requests

response = requests.post(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "workoutStudioId": "6ad6af358bfd50368bfee337",
    },
)

data = response.json()["data"]
```

### Example response (201 Created)

```json
{
  "data": {
    "id": "6ad6af358bfd50368bfee337",
    "name": "Home workouts"
  }
}
```

## Revoke a client's access to a workout studio

`DELETE https://api.hubfit.com/v1/clients/{clientId}/workout-studios/{workoutStudioId}`

Revokes the client's access to the workout studio, as removing them under Manage Access in the app does. It disappears from their app, and Workout Studio with it once they have no workout studios left. If they didn't have access, nothing changes. Requires `on-demand:write`.

### Path parameters

- `clientId` (string, required): The client's `id`.
- `workoutStudioId` (string, required): A workout studio `id` from `GET /workout-studios`.

### Returns

The client no longer has access.

### Example request

cURL:

```bash
curl -X DELETE https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios/6ad6af358bfd50368bfee337 \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios/6ad6af358bfd50368bfee337", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.delete(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workout-studios/6ad6af358bfd50368bfee337",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": {
    "id": "6ad6af165d04c7155d033418",
    "revoked": true
  }
}
```

## List recipe books

`GET https://api.hubfit.com/v1/recipe-books`

Every recipe book in the workspace, newest first, to pass one's `id` when granting a client access. A workspace has no more than 100, so they all come in one response, without paging. Requires `on-demand:write`.

### Returns

Every recipe book in the workspace.

### Example request

cURL:

```bash
curl https://api.hubfit.com/v1/recipe-books \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/recipe-books", {
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.get(
    "https://api.hubfit.com/v1/recipe-books",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": [
    {
      "id": "6ad6af48098ec0490990534a",
      "name": "High-protein meals"
    }
  ]
}
```

## Grant a client access to a recipe book

`POST https://api.hubfit.com/v1/clients/{clientId}/recipe-books`

Grants the client access to the recipe book, as adding them under Manage Access in the app does: it shows in their app and they get a notification. Recipe Books appears in their app if it wasn't there. If they already have access, nothing changes and nothing is sent: that's a `200` instead of a `201`, so a retry is safe. Requires `on-demand:write`.

### Headers

- `Idempotency-Key` (string): Any unique string, such as a UUID, up to 255 characters. Retrying with the same key within 24 hours returns the first response instead of repeating the write. See [Idempotency](https://hubfit.com/developers/idempotency).

### Path parameters

- `clientId` (string, required): The client's `id`.

### Body parameters

- `recipeBookId` (string, required)

### Returns

`200`: The client already had access, so nothing changed. `201`: Access granted.

### Example request

cURL:

```bash
curl -X POST https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books \
  -H "Authorization: Bearer $HUBFIT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "recipeBookId": "6ad6af48098ec0490990534a"
  }'
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    recipeBookId: "6ad6af48098ec0490990534a",
  }),
});

const { data } = await response.json();
```

Python:

```python
import os
import uuid
import requests

response = requests.post(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "recipeBookId": "6ad6af48098ec0490990534a",
    },
)

data = response.json()["data"]
```

### Example response (201 Created)

```json
{
  "data": {
    "id": "6ad6af48098ec0490990534a",
    "name": "High-protein meals"
  }
}
```

## Revoke a client's access to a recipe book

`DELETE https://api.hubfit.com/v1/clients/{clientId}/recipe-books/{recipeBookId}`

Revokes the client's access to the recipe book, as removing them under Manage Access in the app does. It disappears from their app, and Recipe Books with it once they have no recipe books left. If they didn't have access, nothing changes. Requires `on-demand:write`.

### Path parameters

- `clientId` (string, required): The client's `id`.
- `recipeBookId` (string, required): A recipe book `id` from `GET /recipe-books`.

### Returns

The client no longer has access.

### Example request

cURL:

```bash
curl -X DELETE https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books/6ad6af48098ec0490990534a \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books/6ad6af48098ec0490990534a", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.delete(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/recipe-books/6ad6af48098ec0490990534a",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": {
    "id": "6ad6af165d04c7155d033418",
    "revoked": true
  }
}
```

## List resource collections

`GET https://api.hubfit.com/v1/resource-collections`

Every resource collection in the workspace, newest first, to pass one's `id` when granting a client access. A workspace has no more than 100, so they all come in one response, without paging. Requires `on-demand:write`.

### Returns

Every resource collection in the workspace.

### Example request

cURL:

```bash
curl https://api.hubfit.com/v1/resource-collections \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/resource-collections", {
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.get(
    "https://api.hubfit.com/v1/resource-collections",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": [
    {
      "id": "6ad6af06142ae30514295008",
      "name": "Getting started"
    }
  ]
}
```

## Grant a client access to a resource collection

`POST https://api.hubfit.com/v1/clients/{clientId}/resource-collections`

Grants the client access to the resource collection, as adding them under Manage Access in the app does: it shows in their app and they get a notification. If they already have access, nothing changes and nothing is sent: that's a `200` instead of a `201`, so a retry is safe. Requires `on-demand:write`.

### Headers

- `Idempotency-Key` (string): Any unique string, such as a UUID, up to 255 characters. Retrying with the same key within 24 hours returns the first response instead of repeating the write. See [Idempotency](https://hubfit.com/developers/idempotency).

### Path parameters

- `clientId` (string, required): The client's `id`.

### Body parameters

- `resourceCollectionId` (string, required)

### Returns

`200`: The client already had access, so nothing changed. `201`: Access granted.

### Example request

cURL:

```bash
curl -X POST https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections \
  -H "Authorization: Bearer $HUBFIT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "resourceCollectionId": "6ad6af06142ae30514295008"
  }'
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    resourceCollectionId: "6ad6af06142ae30514295008",
  }),
});

const { data } = await response.json();
```

Python:

```python
import os
import uuid
import requests

response = requests.post(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "resourceCollectionId": "6ad6af06142ae30514295008",
    },
)

data = response.json()["data"]
```

### Example response (201 Created)

```json
{
  "data": {
    "id": "6ad6af06142ae30514295008",
    "name": "Getting started"
  }
}
```

## Revoke a client's access to a resource collection

`DELETE https://api.hubfit.com/v1/clients/{clientId}/resource-collections/{resourceCollectionId}`

Revokes the client's access to the resource collection, as removing them under Manage Access in the app does. It disappears from their app. If they didn't have access, nothing changes. Requires `on-demand:write`.

### Path parameters

- `clientId` (string, required): The client's `id`.
- `resourceCollectionId` (string, required): A resource collection `id` from `GET /resource-collections`.

### Returns

The client no longer has access.

### Example request

cURL:

```bash
curl -X DELETE https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections/6ad6af06142ae30514295008 \
  -H "Authorization: Bearer $HUBFIT_API_KEY"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections/6ad6af06142ae30514295008", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
  },
});

const { data } = await response.json();
```

Python:

```python
import os
import requests

response = requests.delete(
    "https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/resource-collections/6ad6af06142ae30514295008",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

data = response.json()["data"]
```

### Example response (200 OK)

```json
{
  "data": {
    "id": "6ad6af165d04c7155d033418",
    "revoked": true
  }
}
```
