Cloud › Config as code
Apply a config file
POST https://devapi.dispralabs.com/v1/cloud/environments/:env/config/apply
Makes the plan again and runs it, in order: groups, variables, volumes, then each service (create, settings, regions, variables, group, domains, volume).
Pass the plan_hash you reviewed: if the environment changed since, the apply is refused with plan_stale and the new plan, so what runs is what you saw. With deploy (default true), every service that was created or changed is deployed. If one step is refused, the apply stops there and answers what it applied before it.
Needs a key with full access.
- Authentication: Secret key (send it as
Authorization: Bearer <key>) - Idempotency: Safe to retry. Send an
Idempotency-Keyheader and repeated calls within 24 hours return the first result.
Parameters
envstring, required: The environment's id. Example:env_01jdk3m9x5h2p8r4t6y1u3i0oaconfigobject, 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}}}plan_hashstring, optional: The plan_hash of the plan you reviewed. Example:pln_7c1e9a2f4b6d8e0a1c3e5f7adeployboolean, optional: Deploy what changed (default true). Example:truepruneboolean, optional: Delete what the file leaves out (never volumes). Example:false
Returns
- 200 The apply result object: What ran.
Errors
| Status | Code | When |
|---|---|---|
| 400 | invalid_config | The file is not valid. The message names every problem, with its key. |
| 404 | not_found | No such object in the key's project (or environment). |
| 409 | plan_stale | The environment changed since the plan: the error carries the new plan. |
| 409 | apply_failed | A step was refused. The changes before it were applied. |
| 409 | account_frozen | The workspace is out of credits: add credits on the dashboard to create, change or deploy. |
Request samples
Dispra Cloud CLI
dcloud apply -f dispra.yaml
# shows the plan, asks, then applies exactly that plan
cURL
curl -X POST "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/apply" \
-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}}},"plan_hash":"pln_7c1e9a2f4b6d8e0a1c3e5f7a","deploy":true,"prune":false}'
Node
const res = await fetch("https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/apply", {
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}}},
"plan_hash": "pln_7c1e9a2f4b6d8e0a1c3e5f7a",
"deploy": true,
"prune": false
}),
});
console.log(await res.json());
Python
import uuid, requests
res = requests.request("POST", "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/apply", 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}}},
"plan_hash": "pln_7c1e9a2f4b6d8e0a1c3e5f7a",
"deploy": True,
"prune": False
})
print(res.json())
Go
body := strings.NewReader(`{"config":{"services":{"api":{"source":{"repo":"acme/api","branch":"main"},"size":{"cpu":"1000m","memory":"1Gi"},"replicas":2}}},"plan_hash":"pln_7c1e9a2f4b6d8e0a1c3e5f7a","deploy":true,"prune":false}`)
req, _ := http.NewRequest("POST", "https://devapi.dispralabs.com/v1/cloud/environments/env_01jdk3m9x5h2p8r4t6y1u3i0oa/config/apply", 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
{
"data": {
"plan_hash": "pln_7c1e9a2f4b6d8e0a1c3e5f7a",
"applied": [{"action":"update","kind":"service","target":"api"}],
"deployments": [{"service":"api","svc":"svc_01jdk3n2f4g6h8j0k2l4z6x8ca","dep":"dep_01jdk4p7q9w1e3r5t7y9u1i3ob"}],
"unmanaged": [],
"warnings": []
}
}
400 invalid_config
{
"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
{
"error": {
"code": "not_found",
"message": "No such object in the key's project (or environment).",
"request_id": "req_7f3a9c21d84be056"
}
}
409 plan_stale
{
"error": {
"code": "plan_stale",
"message": "The environment changed since the plan: the error carries the new plan.",
"request_id": "req_7f3a9c21d84be056"
}
}
409 apply_failed
{
"error": {
"code": "apply_failed",
"message": "A step was refused. The changes before it were applied.",
"request_id": "req_7f3a9c21d84be056"
}
}
409 account_frozen
{
"error": {
"code": "account_frozen",
"message": "The workspace is out of credits: add credits on the dashboard to create, change or deploy.",
"request_id": "req_7f3a9c21d84be056"
}
}