# Variation Group

#### Definition

A **Variation Group** is a single traffic split within a campaign. It defines who can enter (via **Targeting**) and how traffic is distributed across **Variations**. Exactly one variation must be the **reference** (control). Allocations in the group must sum to 100.

#### Payload Properties

A variation group has many properties. When creating or updating a variation group, the payload can include the following fields:

* **`id`** (String, *optional*) – The variation group's unique ID. Include this only when updating an existing variation group.
* `name` (String, optional) — Display name for the group.
* `variations` (Array\<Variation>, **required**) — At least one reference and one test recommended.
* `targeting` (Object, optional) — Entry rules:
  * `targeting_groups` (Array\<Object>, optional) — OR between groups.
    * Each group has `targetings` (Array\<Object>, AND within the group):
      * `key` (String, **required**) — Targeting Key name.
      * `operator` (String, **required**) — e.g., `EQUALS`, `IN`, `CONTAINS`, `MATCHES_REGEX` (set varies by platform).
      * `value` (Any, **required**) — Comparison value (string/number/boolean/array).

**Example Variation group Payload:**

```json
{
  "name": "Logged-in Users",
  "variations": [
    { "name": "Original", "reference": true, "allocation": 50 },
    {
      "name": "Variation A",
      "reference": false,
      "allocation": 50,
      "modifications": {
        "type": "FLAG",
        "value": { "new-nav": true }
      }
    }
  ],
  "targeting": {
    "targeting_groups": [
      {
        "targetings": [
          { "key": "isLoggedIn", "operator": "EQUALS", "value": true }
        ]
      }
    ]
  }
}
```

#### Error Codes

Error scenarios for campaigns largely follow the general codes:

* **InvalidPayload** – The campaign payload is missing required fields or has invalid values (e.g., missing name or type).
* **ParentNotFound** – (Not usually applicable to campaigns since they have no parent in this schema; this might be returned if an account or environment context is wrong, but not in the resource schema context of parent-child).
* **PermissionDenied** – The user lacks permission to create or modify campaigns (for instance, not having the rights to create campaigns in the account).
* **DuplicateRef** – A campaign with the same reference already exists. For example, trying to create a campaign with a name or key that conflicts with an existing one could trigger this.
* **InvalidDependency** – If the campaign references something that doesn’t exist. This is rare at the campaign level, but could occur if sub\_tests or audiences reference invalid IDs (e.g., an audience ID that is not found).
