---
title: "Bulk upsert environment variables"
method: POST
path: "/api/v1/apps/{appId}/env"
tags: ["Apps"]
---

# Bulk upsert environment variables

`POST /api/v1/apps/{appId}/env`

## Request

- Base URL: `https://app.khotan.com`
- URL: `https://app.khotan.com/api/v1/apps/{appId}/env`
- Auth: one of:
  - HTTP bearer
  - API key in header `x-api-key`

Creates or updates many environment variables for the given environments (defaults to all when target is omitted) in one request; other environments keep their value. Requires an API key whose role includes developer. Writes are not transactional: the response reports upsertedKeys and failedKeys, and earlier successful writes remain applied — retry the failed subset. Changes apply on the next deployment; trigger a redeploy to make them live.

## Path parameters

- `appId` string, required

## Request body

- object
  - `variables` object[], required
    - `key` string, required
    - `value` string, required
  - `target` string[]

## Response `200`

The partial result: which keys were upserted and which failed.

- object
  - `upsertedKeys` string[], required
  - `failedKeys` string[], required
  - `requiresRedeploy` boolean, required

## Other responses

- `400`: The request was malformed or failed validation.
- `401`: Authentication is missing or invalid.
- `404`: The resource was not found.
- `409`: Response.
- `429`: Too many requests; retry after the indicated delay.

---

[API](https://skmtc.dev/khotan/apis/khotan-api.md) - [All operations](https://skmtc.dev/khotan/apis/khotan-api/llms.txt) - [OpenAPI document](https://skmtc.dev/khotan/apis/khotan-api/revisions/90b512a53e42?raw)
