---
title: "Create or update variables (optionally redeploy)"
method: POST
path: "/projects/{projectId}/env"
tags: ["Environment"]
---

# Create or update variables (optionally redeploy)

`POST /projects/{projectId}/env`

## Request

- Base URL: `https://hostingsurge.com/api/v1`
- URL: `https://hostingsurge.com/api/v1/projects/{projectId}/env`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `__Host-hs_session`

## Path parameters

- `projectId` string, uuid, required

## Request body

- object
  - `variables` object[], required
    - `key` string, required
    - `value` string, required
    - `targets` string[]: the environments this value is for (default: all three). Other environments keep the value they have
    - `gitBranch` string, nullable: a preview value for this Git branch only (targets must be exactly ["preview"]); it replaces the preview value on that branch's preview
    - `id` string, uuid: update this entry (from GET …/env) instead of the one with the same environments
    - `secret` boolean: secret values are never returned unless revealed with env:reveal
    - `buildtime` boolean
    - `runtime` boolean
  - `redeploy` boolean

## Response `200`

Saved

- object
  - `items` object[], required
    - `id` string, uuid, required
    - `key` string, required
    - `value` string, nullable, required: null when secret and not revealed
    - `secret` boolean, required
    - `targets` string[], required: the environments this entry's value is for; one name can have one entry per environment
    - `gitBranch` string, nullable, required: set: a preview value for this Git branch only
    - `buildtime` boolean, required
    - `runtime` boolean, required
    - `updatedAt` string, required: ISO-8601 timestamp
  - `deployment` object, nullable, required
    - `id` string, uuid, required
    - `projectId` string, uuid, required
    - `state` 'queued' | 'building' | 'deploying' | 'ready' | 'error' | 'canceled', required
    - `target` 'production' | 'preview', required
    - `isCurrent` boolean, required: this deployment serves production traffic now
    - `trigger` 'create' | 'redeploy' | 'git_push' | 'api' | 'cli' | 'upload' | 'rollback' | 'config_change' | 'builder' | 'promote' | 'deploy_hook', required
    - `commit` object, nullable, required
      - `sha` string, required
      - `message` string, nullable, required
      - `author` string, nullable, required
      - `branch` string, nullable, required
    - `url` string, nullable, required
    - `creator` object, nullable, required
      - `id` string, uuid, required
      - `name` string, required
    - `createdAt` string, required: ISO-8601 timestamp
    - `startedAt` string, nullable, required: ISO-8601 timestamp
    - `readyAt` string, nullable, required: ISO-8601 timestamp
    - `durationMs` integer, nullable, required
    - `errorMessage` string, nullable, required
    - `retryOf` string, uuid, nullable: set on a deployment the platform started by itself because the hosting engine ran the build of this deployment twice and removed its own build container: the deployment it starts again (same request: target, branch, trigger and options)
    - `retriedAs` string, uuid, nullable: set on a deployment that ended in error because the hosting engine ran its build twice (nothing in the code failed) and that the platform started again automatically: the new deployment. Its outcome is the outcome of this request, so a client waiting for this deployment follows that one. Never set on a retry (a request is started again at most once)

## Other responses

- `400`: Invalid request (code invalid_request)
- `401`: Missing or invalid session/token (code unauthorized)
- `403`: Authenticated but not permitted (code forbidden)
- `404`: Not found or not visible to the caller (code not_found)
- `409`: Conflicting state (code conflict)
- `429`: Too many requests (code rate_limited); see Retry-After
- `503`: Hosting engine unavailable (code provider_unavailable)

---

[API](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api.md) · [All operations](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/revisions/4d08337cdff1?raw)
