*Cloud › Config as code*

# Plan a config file

```http
POST https://devapi.dispralabs.com/v1/cloud/environments/:env/config/plan
```

Shows what applying a `dispra.yaml` file to the environment would change, step by step, without changing anything.

What the file leaves out is left as it is. Services, volumes and variables the file does not name are listed in `unmanaged`; pass `prune: true` to plan deleting them (volumes are never deleted). Variable values are compared on the server and never returned. Needs `full` access, because comparing reads secret values.

Needs a key with `full` access.

- **Authentication:** Secret key (send it as `Authorization: Bearer <key>`)
- **Idempotency:** Safe to retry. Send an `Idempotency-Key` header and repeated calls within 24 hours return the first result.

## Parameters

- `env` (string, required): The environment's id. Example: `env_01jdk3m9x5h2p8r4t6y1u3i0oa`
- `config` (object, required): dispra.yaml as JSON: groups, variables, services and volumes. See the dispra.yaml guide. Example: `{"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}}`
- `prune` (boolean, optional): Plan deleting what the file leaves out. Example: `false`

## Returns

- **200** [The config plan object](https://docs.dispralabs.com/objects/the-config-plan-object.md): The plan.

## Errors

| Status | Code | When |
|---|---|---|
| 400 | [invalid_config](https://docs.dispralabs.com/errors.md#invalid_config) | The file is not valid. The message names every problem, with its key. |
| 404 | [not_found](https://docs.dispralabs.com/errors.md#not_found) | No such object in the key's project (or environment). |

## Request samples

### Dispra Cloud CLI

```bash
dcloud plan -f dispra.yaml
```

### cURL

```bash
curl -X POST "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/plan" \
  -H "Authorization: Bearer dsp_live_YOUR_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"config":{"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}},"prune":false}'
```

### Node

```javascript
const res = await fetch("https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/plan", {
  method: "POST",
  headers: { Authorization: "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({
    "config": {"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}},
    "prune": false
  }),
});
console.log(await res.json());
```

### Python

```python
import uuid, requests
res = requests.request("POST", "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/plan", headers={"Authorization": "Bearer dsp_live_YOUR_KEY", "Idempotency-Key": str(uuid.uuid4())}, json={
  "config": {"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}},
  "prune": False
})
print(res.json())
```

### Go

```go
body := strings.NewReader(`{"config":{"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}},"prune":false}`)
req, _ := http.NewRequest("POST", "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/plan", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer dsp_live_YOUR_KEY")
req.Header.Set("Idempotency-Key", uuid.NewString())
res, _ := http.DefaultClient.Do(req)
```

## Responses

### 200

```json
{
  "data": {
    "plan_hash": "pln_7c1e9a2f4b6d8e0a1c3e5f7a",
    "changes": [{"action":"update","kind":"service","target":"api","fields":[{"field":"replicas","from":1,"to":2}]}],
    "unmanaged": ["service legacy-worker"],
    "warnings": ["variables.STRIPE_KEY is a secret without a value"]
  }
}
```

### 400 invalid_config

```json
{
  "error": {
    "code": "invalid_config",
    "message": "The file is not valid. The message names every problem, with its key.",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

### 404 not_found

```json
{
  "error": {
    "code": "not_found",
    "message": "No such object in the key's project (or environment).",
    "request_id": "req_7f3a9c21d84be056"
  }
}
```

## Related

- [Config as code](https://docs.dispralabs.com/features/config-as-code.md)
- [config.apply](https://docs.dispralabs.com/flows/config-apply.md)
