---
title: "Create (overwrite) variants for a feature in an environment"
method: PUT
path: "/api/admin/projects/{projectId}/features/{featureName}/environments/{environment}/variants"
tags: ["Features"]
---

# Create (overwrite) variants for a feature in an environment

`PUT /api/admin/projects/{projectId}/features/{featureName}/environments/{environment}/variants`

This overwrites the current variants for the feature flag in the :featureName parameter for the :environment parameter.

The backend will validate the input for the following invariants:

* If there are variants, there needs to be at least one variant with `weightType: variable`

* The sum of the weights of variants with `weightType: fix` must be strictly less than 1000 (< 1000)

The backend will also distribute remaining weight up to 1000 after adding the variants with `weightType: fix` together amongst the variants of `weightType: variable`

## Path parameters

- `projectId` string, required
- `featureName` string, required
- `environment` string, required

## Request body

- VariantSchema[] — A list of variants
  - `name` string, required — The variants name. Is unique for this feature flag
  - `weight` number, required — The weight is the likelihood of any one user getting this variant. It is a number between 0 and 1000. See the section on [variant weights](https://docs.getunleash.io/concepts/feature-flag-variants#variant-weight) for more information
  - `weightType` 'variable' | 'fix' — Set to fix if this variant must have exactly the weight allocated to it. If the type is variable, the weight will adjust so that the total weight of all variants adds up to 1000
  - `stickiness` string — [Stickiness](https://docs.getunleash.io/concepts/feature-flag-variants#variant-stickiness) is how Unleash guarantees that the same user gets the same variant every time
  - `payload` object — Extra data configured for this variant
    - `type` 'json' | 'csv' | 'string' | 'number', required — The type of the value. Commonly used types are string, number, json and csv.
    - `value` string, required — The actual value of payload
  - `overrides` OverrideSchema[] — Overrides assigning specific variants to specific users. The weighting system automatically assigns users to specific groups for you, but any overrides in this list will take precedence.
    - `contextName` string, required — The name of the context field used to determine overrides
    - `values` string[], required — Which values that should be overriden

## Response `200`

featureVariantsSchema

- FeatureVariantsSchema — A versioned collection of feature flag variants.
  - `version` integer, required — The version of the feature variants schema.
  - `variants` VariantSchema[], required — All variants defined for a specific feature flag.
    - `name` string, required — The variants name. Is unique for this feature flag
    - `weight` number, required — The weight is the likelihood of any one user getting this variant. It is a number between 0 and 1000. See the section on [variant weights](https://docs.getunleash.io/concepts/feature-flag-variants#variant-weight) for more information
    - `weightType` 'variable' | 'fix' — Set to fix if this variant must have exactly the weight allocated to it. If the type is variable, the weight will adjust so that the total weight of all variants adds up to 1000
    - `stickiness` string — [Stickiness](https://docs.getunleash.io/concepts/feature-flag-variants#variant-stickiness) is how Unleash guarantees that the same user gets the same variant every time
    - `payload` object — Extra data configured for this variant
      - `type` 'json' | 'csv' | 'string' | 'number', required — The type of the value. Commonly used types are string, number, json and csv.
      - `value` string, required — The actual value of payload
    - `overrides` OverrideSchema[] — Overrides assigning specific variants to specific users. The weighting system automatically assigns users to specific groups for you, but any overrides in this list will take precedence.
      - `contextName` string, required — The name of the context field used to determine overrides
      - `values` string[], required — Which values that should be overriden

## Other responses

- `400` — The request data does not match what we expect.
- `401` — Authorization information is missing or invalid. Provide a valid API token as the `authorization` header, e.g. `authorization:*.*.my-admin-token`.
- `403` — The provided user credentials are valid, but the user does not have the necessary permissions to perform this operation

---

[API](https://skmtc.dev/unleash/apis/unleash-api-3.md) · [All operations](https://skmtc.dev/unleash/apis/unleash-api-3/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/unleash/unleash-api-3/revisions/b2c3116e633e/schema)
