> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hustapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pipelines

> Liste, consulte, crie, edite e exclua funis

Uma pipeline é um funil. Ela agrupa as etapas e, dentro delas, os cards.

## Objeto Pipeline

| Campo | Tipo | Descrição |
| - | - | - |
| `id` | `integer` | Identificador. |
| `name` | `string` | Nome do funil. |
| `description` | `string \| null` | Descrição. |
| `type` | `string` | `task`, `lead` ou `internal`. |
| `active` | `boolean` | Só pipelines ativas são listadas. |
| `template` | `object \| null` | Modelo aplicado a novos cards: `{ "description": string, "checklists": string[] }`. |
| `department` | `object \| null` | Departamento que restringe a visibilidade. |
| `stage` | `array` | Etapas com os cards. Só em [Obter pipeline](#obter-pipeline). |

## Listar pipelines

```http theme={null}
GET /task/pipeline
```

Retorna as pipelines ativas da empresa. Pipelines vinculadas a um departamento só aparecem para usuários desse departamento.

```bash theme={null}
curl https://api.hustapp.com/task/pipeline \
  -H "Authorization: Bearer SEU_TOKEN"
```

```json Resposta theme={null}
[
  {
    "id": 1,
    "name": "Funil Padrão",
    "description": null,
    "type": "lead",
    "active": true,
    "template": { "checklists": [], "description": "" },
    "department": null
  }
]
```

## Obter pipeline

```http theme={null}
GET /task/pipeline/{id}
```

Retorna a pipeline com as etapas, ordenadas por `sequence`, e todos os cards de cada etapa. É a rota para montar o Kanban.

Cada card vem com `user`, `subTasks`, `calleds` (com o contato) e `contacts`.

> [!WARNING]
>
> A resposta não é paginada: traz todos os cards da pipeline. Em funis grandes, ela pode ser pesada.

```bash cURL theme={null}
curl https://api.hustapp.com/task/pipeline/1 \
  -H "Authorization: Bearer SEU_TOKEN"
```

```javascript Node.js theme={null}
const res = await fetch("https://api.hustapp.com/task/pipeline/1", {
  headers: { Authorization: `Bearer ${token}` },
});

const pipeline = await res.json();

for (const stage of pipeline.stage) {
  console.log(stage.name, stage.tasks.length);
}
```

```python Python theme={null}
import requests

pipeline = requests.get(
    "https://api.hustapp.com/task/pipeline/1",
    headers={"Authorization": f"Bearer {token}"},
).json()

for stage in pipeline["stage"]:
    print(stage["name"], len(stage["tasks"]))
```

```php PHP theme={null}
<?php
$ch = curl_init('https://api.hustapp.com/task/pipeline/1');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $token],
]);

$pipeline = json_decode(curl_exec($ch), true);
curl_close($ch);

foreach ($pipeline['stage'] as $stage) {
    echo $stage['name'] . ': ' . count($stage['tasks']) . PHP_EOL;
}
```

```pascal Delphi theme={null}
uses
  System.Net.HttpClient, System.JSON, System.SysUtils;

var
  HttpClient: THTTPClient;
  Response: IHTTPResponse;
  Pipeline: TJSONObject;
  Stages: TJSONArray;
  I: Integer;
begin
  HttpClient := THTTPClient.Create;
  try
    HttpClient.CustomHeaders['Authorization'] := 'Bearer ' + Token;
    Response := HttpClient.Get('https://api.hustapp.com/task/pipeline/1');

    Pipeline := TJSONObject.ParseJSONValue(Response.ContentAsString) as TJSONObject;
    try
      Stages := Pipeline.GetValue<TJSONArray>('stage');
      for I := 0 to Stages.Count - 1 do
        Writeln(Format('%s: %d', [
          Stages.Items[I].GetValue<string>('name'),
          Stages.Items[I].GetValue<TJSONArray>('tasks').Count
        ]));
    finally
      Pipeline.Free;
    end;
  finally
    HttpClient.Free;
  end;
end;
```

```json Resposta theme={null}
{
  "id": 1,
  "name": "Funil Padrão",
  "type": "lead",
  "stage": [
    {
      "id": 10,
      "name": "Novo lead",
      "color": "#0098DA",
      "sequence": 0,
      "status": "pending",
      "config": null,
      "tasks": [
        {
          "id": 501,
          "title": "Empresa X",
          "status": "pending",
          "priority": "high",
          "dateStart": "2026-10-01T12:00:00.000Z",
          "dateDue": null,
          "valueUnique": 1500,
          "valueRecurring": 200,
          "sequence": 0,
          "type": "lead",
          "user": { "id": 12, "name": "Maria" },
          "subTasks": [],
          "calleds": [],
          "contacts": []
        }
      ]
    }
  ]
}
```

## Criar pipeline

```http theme={null}
POST /task/pipeline
```

| Campo | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `name` | `string` | Sim | Nome. |
| `type` | `string` | Não | `task`, `lead` ou `internal`. |

```bash theme={null}
curl -X POST https://api.hustapp.com/task/pipeline \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Funil de Vendas", "type": "lead" }'
```

Retorna `200` com a pipeline criada, ainda sem etapas. Crie as etapas em [Etapas](/crm/etapas.md), ou deixe que o Hust crie as etapas padrão ao adicionar o primeiro card.

## Editar pipeline

```http theme={null}
PUT /task/pipelines/{id}
```

> [!NOTE]
>
> O caminho usa o plural: `/task/pipelines`.

| Campo | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `name` | `string` | Sim | Nome. |
| `type` | `string` | Sim | `task`, `lead` ou `internal`. |
| `department` | `object` | Não | `{ id }` para restringir ao departamento. Omita ou envie `null` para remover a restrição. |

```bash theme={null}
curl -X PUT https://api.hustapp.com/task/pipelines/1 \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Funil de Vendas", "type": "lead", "department": { "id": 7 } }'
```

| Status | Corpo |
| - | - |
| `200` | `{ "message": "Pipeline atualizada com sucesso!", "pipeline": { ... } }` |
| `400` | `{ "message": "O nome da pipeline é obrigatório." }` ou `"Tipo de pipeline inválido."` |
| `404` | `{ "message": "Pipeline não encontrada." }` |

## Excluir pipeline

```http theme={null}
DELETE /task/pipelines/{id}
```

Exclui a pipeline e as etapas. Só é permitido quando nenhuma etapa tem cards.

| Status | Corpo |
| - | - |
| `200` | `{ "message": "Pipeline excluída com sucesso." }` |
| `404` | Etapa com cards: `{ "message": "Não é possível excluir a pipeline...", "stage": { "id": 10, "name": "Novo lead" } }` |
| `404` | `{ "message": "Pipeline não encontrada." }` |

## Reordenar etapas

```http theme={null}
PUT /task/pipeline/sequence
```

Envie todas as etapas da pipeline com a nova ordem. Retorna `200` com `true`.

```json theme={null}
[
  { "id": 10, "sequence": 0 },
  { "id": 11, "sequence": 1 },
  { "id": 12, "sequence": 2 }
]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.