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

# Get deployment

> Consulta o status da tentativa de publicação mais recente de um chat

Consulta o status da tentativa de publicação mais recente de um chat, ou da tentativa indicada por `deploymentId`. A tentativa mais recente pode ainda estar em build, ou pode ter falhado enquanto uma versão anterior continua no ar. Use `liveUrl` para obter a URL da versão que está no ar agora. Se a publicação ainda não estiver em um estado final, o endpoint sincroniza o status com a Vercel antes de responder.

## Requisição

```
GET /api/chat/{chatId}/deployment
```

### Cabeçalhos

| Cabeçalho | Obrigatório | Descrição |
| - | - | - |
| `Authorization` | Sim | `Bearer macaly_...` |

### Parâmetros de caminho

| Parâmetro | Tipo | Descrição |
| - | - | - |
| `chatId` | string | O ID do chat |

### Parâmetros de consulta

| Parâmetro | Obrigatório | Descrição |
| - | - | - |
| `deploymentId` | Não | O `id` ou `deploymentId` retornado por [`POST /deploy`](/docs/pt-BR/api/deploy). Sem ele, o endpoint retorna a tentativa de publicação mais recente do chat. |

### Exemplo de requisição

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://www.macaly.com/api/chat/abc123/deployment?deploymentId=jzga0sttml37v6mbizb8tk1x" \
    -H "Authorization: Bearer macaly_abc123..."
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    `https://www.macaly.com/api/chat/${chatId}/deployment?deploymentId=${deploymentId}`,
    {
      headers: {
        'Authorization': 'Bearer macaly_abc123...',
      },
    }
  );

  const data = await response.json();
  console.log(data.status, data.liveUrl);
  ```

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

  response = requests.get(
      f'https://www.macaly.com/api/chat/{chat_id}/deployment',
      params={'deploymentId': deployment_id},
      headers={
          'Authorization': 'Bearer macaly_abc123...',
      },
  )

  data = response.json()
  print(data['status'], data['liveUrl'])
  ```
</CodeGroup>

## Resposta

### Publicação concluída

```json theme={null}
{
  "id": "jzga0sttml37v6mbizb8tk1x",
  "url": "https://macaly-staging-abc123.macaly.app",
  "status": "READY",
  "deploymentId": "dpl_HKLBd2QDTwq58AMUJiaMyUzk8WUw",
  "createdAt": "2025-01-12T21:18:54.906Z",
  "error": null,
  "domain": "macaly-staging-abc123.macaly.app",
  "domains": [
    {
      "domain": "macaly-staging-abc123.macaly.app",
      "verified": true,
      "isCustomDomain": false
    }
  ],
  "liveUrl": "https://macaly-staging-abc123.macaly.app"
}
```

### Nenhuma publicação

```json theme={null}
{
  "id": null,
  "url": null,
  "status": null,
  "deploymentId": null,
  "createdAt": null,
  "error": null,
  "domain": null,
  "domains": [
    {
      "domain": "macaly-staging-abc123.macaly.app",
      "verified": true,
      "isCustomDomain": false
    }
  ],
  "liveUrl": null
}
```

### Publicação com falha

Uma republicação com falha mantém a versão anterior no ar, então `liveUrl` continua preenchido.

```json theme={null}
{
  "id": "jzga0sttml37v6mbizb8tk1x",
  "url": "https://macaly-staging-abc123.macaly.app",
  "status": "ERROR",
  "deploymentId": "dpl_HKLBd2QDTwq58AMUJiaMyUzk8WUw",
  "createdAt": "2025-01-12T21:18:54.906Z",
  "error": ["Build failed: Module not found"],
  "domain": "macaly-staging-abc123.macaly.app",
  "domains": [],
  "liveUrl": "https://macaly-staging-abc123.macaly.app"
}
```

### Campos da resposta

| Campo | Tipo | Descrição |
| - | - | - |
| `id` | string \| null | ID da publicação no banco de dados (null se nunca foi publicado) |
| `url` | string \| null | URL da publicação |
| `status` | string \| null | Status do deployment na Vercel (veja abaixo) |
| `deploymentId` | string \| null | ID do deployment na Vercel |
| `createdAt` | string \| null | Timestamp ISO da criação da publicação |
| `error` | string\[] \| null | Mensagens de erro, se a publicação falhou |
| `domain` | string \| null | Domínio principal da publicação |
| `domains` | array | Todos os domínios conectados |
| `domains[].domain` | string | Nome do domínio |
| `domains[].verified` | boolean | Indica se o domínio foi verificado |
| `domains[].isCustomDomain` | boolean | Indica se é um domínio personalizado |
| `liveUrl` | string \| null | URL da versão no ar (null se nada estiver no ar) |

### Valores de status da publicação

| Status | Descrição |
| - | - |
| `QUEUED` | A publicação está na fila |
| `BUILDING` | O build está em andamento |
| `READY` | Publicação concluída com êxito |
| `ERROR` | A publicação falhou |
| `CANCELED` | A publicação foi cancelada |
| `UNPUBLISHED` | A publicação foi despublicada |

## Códigos de status

| Código | Descrição |
| - | - |
| 200 | Sucesso (mesmo que não exista publicação, retorna campos null) |
| 401 | Chave de API inválida ou ausente |
| 403 | O chat não pertence ao seu workspace |
| 404 | Chat não encontrado, ou `deploymentId` não corresponde a nenhuma publicação deste chat |

## Padrão de consulta periódica

Passe o `id` retornado por `POST /deploy` como `deploymentId`.

```bash theme={null}
while true; do
  DEPLOYMENT=$(curl -s "https://www.macaly.com/api/chat/$CHAT_ID/deployment?deploymentId=$DEPLOYMENT_ID" \
    -H "Authorization: Bearer macaly_...")

  STATUS=$(echo $DEPLOYMENT | jq -r '.status')
  echo "Status: $STATUS"

  if [[ $STATUS == "READY" ]]; then
    echo "Deployed: $(echo $DEPLOYMENT | jq -r '.liveUrl')"
    break
  elif [[ $STATUS == "ERROR" ]]; then
    echo "Failed: $(echo $DEPLOYMENT | jq -r '.error')"
    break
  fi

  sleep 3
done
```


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