# Workflows

> Your workflows, and adding a client to one or taking them out.

Source: https://hubfit.com/developers/api/workflows


A workflow sends each client in it a coach's steps on a schedule, such as messages, notifications, questionnaires, resources, notes and tasks. In a day-number workflow each client starts on their own day 1; a date-based one runs on calendar dates, the same for everyone. Steps go out at their time in each client's timezone.

Endpoints:

- `GET /v1/workflows`: [List workflows](https://hubfit.com/developers/api/workflows#list-workflows)
- `POST /v1/clients/{clientId}/workflows`: [Add a client to a workflow](https://hubfit.com/developers/api/workflows#add-client-to-workflow)
- `DELETE /v1/clients/{clientId}/workflows/{workflowId}`: [Remove a client from a workflow](https://hubfit.com/developers/api/workflows#remove-client-from-workflow)

## Workflow object

### Attributes

- `id` (string): Its unique ID.
- `name` (string)
- `mode` (enum): `day_number_based`: each client starts on their own day 1 and steps run on day numbers. `date_based`: steps run on calendar dates, the same for every client. Known values `day_number_based`, `date_based`.

### Example

```json
{
  "id": "6ad6af991ca5129a1ca6a597",
  "name": "Example",
  "mode": "day_number_based"
}
```

## Client workflow object

### Attributes

- `id` (string): Its unique ID.
- `name` (string)
- `mode` (enum): `day_number_based`: each client starts on their own day 1 and steps run on day numbers. `date_based`: steps run on calendar dates, the same for every client. Known values `day_number_based`, `date_based`.
- `startDate` (date): The client's day 1, in their own calendar: before today if they started past day 1. In a date-based workflow, the day they were added.

### Example

```json
{
  "id": "6ad6af5406411d53063f8a52",
  "name": "Example",
  "mode": "day_number_based",
  "startDate": "2026-03-02"
}
```

## List workflows

`GET https://api.hubfit.com/v1/workflows`

Every workflow in the workspace, newest first, to pass one's `id` when adding a client. A workspace has no more than 25, so they all come in one response, without paging. Requires `workflows:write`.

### Returns

Every workflow in the workspace.

### Example request

cURL:

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

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/workflows", {
  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/workflows",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

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

### Example response (200 OK)

```json
{
  "data": [
    {
      "id": "6ad6af991ca5129a1ca6a597",
      "name": "Example",
      "mode": "day_number_based"
    }
  ]
}
```

## Add a client to a workflow

`POST https://api.hubfit.com/v1/clients/{clientId}/workflows`

Adds the client to the workflow, as adding them under Manage Access in the app does. They get every step from the start of today, including any due earlier today, and none from earlier days. In a day-number workflow they start today on `startDay`, or day 1 if you leave it out; a date-based workflow follows its own dates and takes no `startDay`. If they're already in it, nothing changes: that's a `200` instead of a `201`, with the start they have, so a retry is safe. Requires `workflows: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

- `workflowId` (string, required)
- `startDay` (integer): The day of a day-number workflow the client is on today, so they skip the days before it. Defaults to 1.

### Returns

`200`: The client was already in the workflow, so nothing changed. `201`: The client was added.

### Example request

cURL:

```bash
curl -X POST https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workflows \
  -H "Authorization: Bearer $HUBFIT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workflows", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.HUBFIT_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});

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

Python:

```python
import os
import uuid
import requests

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

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

### Example response (201 Created)

```json
{
  "data": {
    "id": "6ad6af5406411d53063f8a52",
    "name": "Example",
    "mode": "day_number_based",
    "startDate": "2026-03-02"
  }
}
```

## Remove a client from a workflow

`DELETE https://api.hubfit.com/v1/clients/{clientId}/workflows/{workflowId}`

Removes the client from the workflow, as removing them under Manage Access in the app does. They get no more of its steps, and what they already got stays. Added back later, they start again. If they weren't in it, nothing changes. Requires `workflows:write`.

### Path parameters

- `clientId` (string, required): The client's `id`.
- `workflowId` (string, required): A workflow `id` from `GET /workflows`.

### Returns

The client is no longer in the workflow.

### Example request

cURL:

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

Node.js:

```javascript
const response = await fetch("https://api.hubfit.com/v1/clients/6ad6af41d3199442d31b2743/workflows/6ad6af991ca5129a1ca6a597", {
  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/workflows/6ad6af991ca5129a1ca6a597",
    headers={"Authorization": f"Bearer {os.environ['HUBFIT_API_KEY']}"},
)

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

### Example response (200 OK)

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