# Déploiements

## POST `/v13/deployments`

**Créer un déploiement (fichiers envoyés avant par /v2/files)**

Demande une clé d’API avec la portée `host:deploy`.

### Corps de la requête

Type de contenu : `application/json`.

| Champ          | Type     | Obligatoire | Description |
| -------------- | -------- | ----------- | ----------- |
| `name`         | string   | Oui         |             |
| `files`        | objet\[] | Oui         |             |
| `files[].file` | string   | Oui         |             |
| `files[].sha`  | string   | Oui         |             |
| `files[].size` | number   | Oui         |             |
| `target`       | string   | Non         |             |

### Réponses

| Code  | Description              | Corps         |
| ----- | ------------------------ | ------------- |
| `200` | Succès                   | `objet`       |
| `400` | Requête invalide         | `VercelError` |
| `401` | Authentification requise | `VercelError` |
| `403` | Accès refusé             | `VercelError` |
| `429` | Trop de requêtes         | `VercelError` |
| `500` | Erreur interne           | `VercelError` |

### Champs de la réponse `200`

| Champ        | Type                                                       | Description |
| ------------ | ---------------------------------------------------------- | ----------- |
| `id`         | string                                                     |             |
| `url`        | string                                                     |             |
| `readyState` | “QUEUED” \| “BUILDING” \| “READY” \| “ERROR” \| “CANCELED” |             |
| `target`     | “production” ou null                                       |             |

### Exemple

```bash
curl -X POST "https://api.host.hgdc.ch/v13/deployments" \
  -H "Authorization: Bearer $VERCEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"exemple","files":[{"file":"exemple","sha":"exemple","size":1}]}'
```

Réponse `200` :

```json
{
  "id": "exemple",
  "url": "exemple",
  "readyState": "QUEUED",
  "target": "production"
}
```

## GET `/v13/deployments/{id}`

**Un déploiement**

Demande une clé d’API avec la portée `host:read`.

### Réponses

| Code  | Description              | Corps         |
| ----- | ------------------------ | ------------- |
| `200` | Succès                   | `objet`       |
| `400` | Requête invalide         | `VercelError` |
| `401` | Authentification requise | `VercelError` |
| `403` | Accès refusé             | `VercelError` |
| `404` | Ressource introuvable    | `VercelError` |
| `429` | Trop de requêtes         | `VercelError` |
| `500` | Erreur interne           | `VercelError` |

### Champs de la réponse `200`

| Champ        | Type                                                       | Description |
| ------------ | ---------------------------------------------------------- | ----------- |
| `id`         | string                                                     |             |
| `url`        | string                                                     |             |
| `readyState` | “QUEUED” \| “BUILDING” \| “READY” \| “ERROR” \| “CANCELED” |             |
| `target`     | “production” ou null                                       |             |

### Exemple

```bash
curl -X GET "https://api.host.hgdc.ch/v13/deployments/<id>" \
  -H "Authorization: Bearer $VERCEL_TOKEN"
```

Réponse `200` :

```json
{
  "id": "exemple",
  "url": "exemple",
  "readyState": "QUEUED",
  "target": "production"
}
```

## GET `/v6/deployments`

**Déploiements, du plus récent au plus ancien**

Demande une clé d’API avec la portée `host:read`.

### Paramètres de requête

| Champ       | Type                      | Obligatoire | Description |
| ----------- | ------------------------- | ----------- | ----------- |
| `projectId` | string                    | Non         |             |
| `limit`     | number                    | Non         |             |
| `until`     | number                    | Non         |             |
| `target`    | “production” \| “preview” | Non         |             |

### Réponses

| Code  | Description              | Corps         |
| ----- | ------------------------ | ------------- |
| `200` | Succès                   | `objet`       |
| `400` | Requête invalide         | `VercelError` |
| `401` | Authentification requise | `VercelError` |
| `403` | Accès refusé             | `VercelError` |
| `429` | Trop de requêtes         | `VercelError` |
| `500` | Erreur interne           | `VercelError` |

### Champs de la réponse `200`

| Champ                      | Type                                                       | Description |
| -------------------------- | ---------------------------------------------------------- | ----------- |
| `deployments`              | objet\[]                                                   |             |
| `deployments[].id`         | string                                                     |             |
| `deployments[].url`        | string                                                     |             |
| `deployments[].readyState` | “QUEUED” \| “BUILDING” \| “READY” \| “ERROR” \| “CANCELED” |             |
| `deployments[].target`     | “production” ou null                                       |             |
| `pagination`               | objet                                                      |             |
| `pagination.count`         | number                                                     |             |
| `pagination.next`          | number ou null                                             |             |

### Exemple

```bash
curl -X GET "https://api.host.hgdc.ch/v6/deployments" \
  -H "Authorization: Bearer $VERCEL_TOKEN"
```

Réponse `200` :

```json
{
  "deployments": [
    {
      "id": "exemple",
      "url": "exemple",
      "readyState": "QUEUED",
      "target": "production"
    }
  ],
  "pagination": {
    "count": 1,
    "next": 1
  }
}
```

## GET `/v3/now/deployments/{id}/events`

**Journal de build en NDJSON (follow=1 : en direct)**

Demande une clé d’API avec la portée `host:read`.

### Réponses

| Code  | Description              | Corps         |
| ----- | ------------------------ | ------------- |
| `200` | Succès                   |               |
| `400` | Requête invalide         | `VercelError` |
| `401` | Authentification requise | `VercelError` |
| `403` | Accès refusé             | `VercelError` |
| `404` | Ressource introuvable    | `VercelError` |
| `429` | Trop de requêtes         | `VercelError` |
| `500` | Erreur interne           | `VercelError` |

### Exemple

```bash
curl -X GET "https://api.host.hgdc.ch/v3/now/deployments/<id>/events" \
  -H "Authorization: Bearer $VERCEL_TOKEN"
```

## PATCH `/v12/deployments/{id}/cancel`

**Annuler un build**

Demande une clé d’API avec la portée `host:deploy`.

### Réponses

| Code  | Description              | Corps         |
| ----- | ------------------------ | ------------- |
| `200` | Succès                   | `objet`       |
| `400` | Requête invalide         | `VercelError` |
| `401` | Authentification requise | `VercelError` |
| `403` | Accès refusé             | `VercelError` |
| `404` | Ressource introuvable    | `VercelError` |
| `429` | Trop de requêtes         | `VercelError` |
| `500` | Erreur interne           | `VercelError` |

### Champs de la réponse `200`

| Champ        | Type                                                       | Description |
| ------------ | ---------------------------------------------------------- | ----------- |
| `id`         | string                                                     |             |
| `url`        | string                                                     |             |
| `readyState` | “QUEUED” \| “BUILDING” \| “READY” \| “ERROR” \| “CANCELED” |             |
| `target`     | “production” ou null                                       |             |

### Exemple

```bash
curl -X PATCH "https://api.host.hgdc.ch/v12/deployments/<id>/cancel" \
  -H "Authorization: Bearer $VERCEL_TOKEN"
```

Réponse `200` :

```json
{
  "id": "exemple",
  "url": "exemple",
  "readyState": "QUEUED",
  "target": "production"
}
```
