

```json
{
  "openapi": "3.0.0",
  "info": {
    "contact": {
      "name": "Team: Car | Slack: #ask-liveops"
    },
    "description": "Targeting Rules is a centralized rule-evaluation service that assigns players a set of variant tags (at authentication time), which downstream services such as Live Content use to select the appropriate content and configuration variants.",
    "title": "Targeting Rules Admin API",
    "version": "1.0.0"
  },
  "tags": [
    {
      "name": "Targeting Rules"
    },
    {
      "name": "Tags"
    }
  ],
  "servers": [
    {
      "url": "https://services.api.unity.com/targeting-rules/v1"
    }
  ],
  "paths": {
    "/projects/{projectId}/environments/{environmentId}/groups": {
      "get": {
        "summary": "Get All Tag Groups",
        "description": "Retrieves all tag groups for the given project and environment.",
        "operationId": "getAllTagGroups",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagGroupsListResponse"
                }
              }
            },
            "description": "A list of tag groups."
          }
        }
      },
      "post": {
        "summary": "Create a Tag Group",
        "description": "Creates a new tag group in the specified project and environment.",
        "operationId": "createTagGroup",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTagGroupRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagGroup"
                }
              }
            },
            "description": "Tag group created successfully."
          }
        }
      }
    },
    "/projects/{projectId}/environments/{environmentId}/groups/{groupId}": {
      "patch": {
        "summary": "Update a Tag Group",
        "description": "Updates a tag group's display name. The group ID is immutable.",
        "operationId": "updateTagGroup",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the tag group, as returned by create or list.",
            "in": "path",
            "name": "groupId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTagGroupRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagGroup"
                }
              }
            },
            "description": "Tag group updated successfully."
          }
        }
      },
      "delete": {
        "summary": "Delete a Tag Group",
        "description": "Deletes a tag group. Tags assigned to this group are un-categorized, not deleted.",
        "operationId": "deleteTagGroup",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the tag group, as returned by create or list.",
            "in": "path",
            "name": "groupId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteTagGroupResponse"
                }
              }
            },
            "description": "Tag group deleted successfully."
          }
        }
      }
    },
    "/projects/{projectId}/environments/{environmentId}/tags": {
      "get": {
        "summary": "Get All Tags",
        "description": "Retrieves all tags for the given project and environment, optionally filtered by status.",
        "operationId": "getAllTags",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Filter tags by status. Defaults to active.",
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "default": "active",
              "enum": [
                "active",
                "hidden",
                "all"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagsListResponse"
                }
              }
            },
            "description": "A list of tags."
          }
        }
      },
      "post": {
        "summary": "Create a Tag",
        "description": "Creates a new tag in the specified project and environment.",
        "operationId": "createTag",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTagRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagDetails"
                }
              }
            },
            "description": "Tag created successfully."
          }
        }
      }
    },
    "/projects/{projectId}/environments/{environmentId}/tags/{tagName}": {
      "patch": {
        "summary": "Update a Tag",
        "description": "Updates a tag's status and/or group assignment.",
        "operationId": "updateTag",
        "tags": [
          "Tags"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The name of the tag.",
            "in": "path",
            "name": "tagName",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTagRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TagDetails"
                }
              }
            },
            "description": "Tag updated successfully."
          }
        }
      }
    },
    "/projects/{projectId}/environments/{environmentId}/targeting/rules": {
      "get": {
        "summary": "Get All Targeting Rules",
        "description": "Retrieves all targeting rules for the given project and environment.",
        "operationId": "getAllTargetingRules",
        "tags": [
          "Targeting Rules"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-name",
            "required": false,
            "schema": {
              "example": "{{releaseName}}",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-id",
            "required": false,
            "schema": {
              "example": "{{releaseId}}",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TargetingRulesResponse"
                }
              }
            },
            "description": "A list of configured targeting rules.",
            "headers": {
              "Content-Range": {
                "description": "paging in the format - items [start]-[end]/[total]",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Creates a new targeting rule.",
        "description": "Creates a new targeting rule in the specified project and environment.",
        "operationId": "createTargetingRule",
        "tags": [
          "Targeting Rules"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-name",
            "required": false,
            "schema": {
              "example": "{{releaseName}}",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-id",
            "required": false,
            "schema": {
              "example": "{{releaseId}}",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TargetingRule"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TargetingRule"
                }
              }
            },
            "description": "Targeting rule created successfully."
          }
        }
      }
    },
    "/projects/{projectId}/environments/{environmentId}/targeting/rules/{targetingRuleName}": {
      "get": {
        "summary": "Retrieve a Single Targeting Rule",
        "description": "Gets a single targeting rule.",
        "operationId": "getTargetingRule",
        "tags": [
          "Targeting Rules"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The name of the targeting rule.",
            "in": "path",
            "name": "targetingRuleName",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-name",
            "required": false,
            "schema": {
              "example": "{{releaseName}}",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-id",
            "required": false,
            "schema": {
              "example": "{{releaseId}}",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TargetingRule"
                }
              }
            },
            "description": "OK - Successful retrieval of the targeting rule."
          }
        }
      },
      "put": {
        "summary": "Update a Single Targeting Rule",
        "description": "Updates a single targeting rule.",
        "operationId": "updateTargetingRule",
        "tags": [
          "Targeting Rules"
        ],
        "parameters": [
          {
            "description": "The ID of the project.",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The ID of the environment.",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "The name of the targeting rule.",
            "in": "path",
            "name": "targetingRuleName",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-name",
            "required": false,
            "schema": {
              "example": "{{releaseName}}",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-id",
            "required": false,
            "schema": {
              "example": "{{releaseId}}",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTargetingRuleRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TargetingRule"
                }
              }
            },
            "description": "OK - Successful update of the targeting rule."
          }
        }
      },
      "delete": {
        "summary": "Deletes a single targeting rule.",
        "description": "Deletes a single targeting rule.",
        "operationId": "deleteTargetingRule",
        "tags": [
          "Targeting Rules"
        ],
        "parameters": [
          {
            "description": "ID of the project",
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "ID of the environment",
            "in": "path",
            "name": "environmentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Name of the targeting rule.",
            "in": "path",
            "name": "targetingRuleName",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-name",
            "required": false,
            "schema": {
              "example": "{{releaseName}}",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "unity-live-release-id",
            "required": false,
            "schema": {
              "example": "{{releaseId}}",
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Targeting rule deleted successfully"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Condition": {
        "description": "A CEL formatted condition to determine if a set of tags is applied or not",
        "type": "string"
      },
      "CreateTagGroupRequest": {
        "properties": {
          "name": {
            "description": "The display name of the group.",
            "example": "Platform",
            "maxLength": 255,
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "CreateTagRequest": {
        "properties": {
          "groupId": {
            "description": "The group to assign this tag to.",
            "type": "string"
          },
          "tagName": {
            "description": "The tag name. Must contain only alphanumeric characters, underscores, dashes, or plus symbols.",
            "example": "beta_users",
            "maxLength": 255,
            "pattern": "^[a-zA-Z0-9_+-]+$",
            "type": "string"
          }
        },
        "required": [
          "tagName"
        ],
        "type": "object"
      },
      "DeleteTagGroupResponse": {
        "properties": {
          "affectedTagCount": {
            "description": "The number of tags that were un-categorized by deleting this group.",
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "affectedTagCount"
        ],
        "type": "object"
      },
      "Metadata": {
        "additionalProperties": true,
        "description": "Free-form metadata for the targeting rule. Any JSON object is accepted.",
        "example": {
          "owner": "live-ops",
          "ticket": "LIVE-123"
        },
        "type": "object"
      },
      "Tag": {
        "description": "A tag to be targeted if the rule condition is true. Must contain only alphanumeric characters, underscores, dashes, or plus symbols.",
        "example": "beta_users",
        "pattern": "^[a-zA-Z0-9_+-]+$",
        "type": "string"
      },
      "TagDetails": {
        "description": "A tag registry entry, tracking usage and organization metadata for a variant tag.",
        "properties": {
          "createdAt": {
            "description": "The timestamp when this tag was created.",
            "format": "date-time",
            "type": "string"
          },
          "groupId": {
            "description": "The group this tag belongs to, if any.",
            "nullable": true,
            "type": "string"
          },
          "lastUsedAt": {
            "description": "The timestamp this tag was last used by a targeting rule save, if ever.",
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "name": {
            "description": "The tag name.",
            "example": "beta_users",
            "pattern": "^[a-zA-Z0-9_+-]+$",
            "type": "string"
          },
          "origin": {
            "enum": [
              "user",
              "predefined"
            ],
            "type": "string"
          },
          "status": {
            "enum": [
              "active",
              "hidden"
            ],
            "type": "string"
          },
          "usageCount": {
            "description": "The number of times this tag has been used across targeting rules.",
            "example": 3,
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "name",
          "usageCount",
          "createdAt",
          "status",
          "origin"
        ],
        "type": "object"
      },
      "TagGroup": {
        "description": "An organizational grouping of tags within a project and environment.",
        "properties": {
          "createdAt": {
            "description": "The timestamp when this group was created.",
            "format": "date-time",
            "type": "string"
          },
          "groupId": {
            "description": "The immutable, server-generated group identifier, assigned at creation.",
            "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
            "type": "string"
          },
          "name": {
            "description": "The display name of the group. Renameable.",
            "example": "Platform",
            "maxLength": 255,
            "type": "string"
          },
          "origin": {
            "enum": [
              "user",
              "predefined"
            ],
            "type": "string"
          }
        },
        "required": [
          "groupId",
          "name",
          "createdAt",
          "origin"
        ],
        "type": "object"
      },
      "TagGroupsListResponse": {
        "items": {
          "$ref": "#/components/schemas/TagGroup"
        },
        "type": "array"
      },
      "TagsListResponse": {
        "items": {
          "$ref": "#/components/schemas/TagDetails"
        },
        "type": "array"
      },
      "TargetingRule": {
        "properties": {
          "bucketingKey": {
            "description": "Optional shared bucketing seed. When set, deterministic rollout/variant bucketing seeds on this value instead of the rule name, so rules sharing a bucketingKey place a player in the same cohort. Omitted = seed on rule name.",
            "pattern": "^[a-zA-Z0-9_+-]+$",
            "type": "string"
          },
          "condition": {
            "$ref": "#/components/schemas/Condition"
          },
          "createdAt": {
            "format": "date-time",
            "type": "string"
          },
          "description": {
            "description": "The targeting rule description",
            "type": "string"
          },
          "enabled": {
            "default": false,
            "type": "boolean"
          },
          "metadata": {
            "$ref": "#/components/schemas/Metadata"
          },
          "name": {
            "description": "The targeting rule name. Must contain only alphanumeric characters, underscores, or dashes.",
            "example": "rule_north-america",
            "pattern": "^[a-zA-Z0-9_-]+$",
            "type": "string"
          },
          "priority": {
            "default": 1000,
            "maximum": 1000,
            "minimum": 0,
            "type": "integer"
          },
          "rolloutPercentage": {
            "default": 100,
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "updatedAt": {
            "format": "date-time",
            "type": "string"
          },
          "variants": {
            "items": {
              "$ref": "#/components/schemas/Variant"
            },
            "maxItems": 5,
            "minItems": 1,
            "type": "array"
          }
        },
        "required": [
          "name",
          "condition",
          "variants"
        ],
        "type": "object"
      },
      "TargetingRulesResponse": {
        "items": {
          "$ref": "#/components/schemas/TargetingRule"
        },
        "type": "array"
      },
      "UpdateTagGroupRequest": {
        "properties": {
          "name": {
            "description": "The new display name of the group.",
            "maxLength": 255,
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "UpdateTagRequest": {
        "properties": {
          "groupId": {
            "description": "The group to assign this tag to. Set to null to un-categorize; omit to leave unchanged.",
            "nullable": true,
            "type": "string",
            "x-go-type": "nullable.Nullable[string]",
            "x-go-type-import": {
              "path": "github.com/oapi-codegen/nullable"
            },
            "x-go-type-skip-optional-pointer": true
          },
          "status": {
            "enum": [
              "active",
              "hidden"
            ],
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpdateTargetingRuleRequest": {
        "properties": {
          "bucketingKey": {
            "description": "Optional shared bucketing seed. When set, deterministic rollout/variant bucketing seeds on this value instead of the rule name, so rules sharing a bucketingKey place a player in the same cohort. Omitted = seed on rule name.",
            "pattern": "^[a-zA-Z0-9_+-]+$",
            "type": "string"
          },
          "condition": {
            "$ref": "#/components/schemas/Condition"
          },
          "description": {
            "description": "The targeting rule description",
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "metadata": {
            "$ref": "#/components/schemas/Metadata"
          },
          "priority": {
            "maximum": 1000,
            "minimum": 0,
            "type": "integer"
          },
          "rolloutPercentage": {
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "variants": {
            "items": {
              "$ref": "#/components/schemas/Variant"
            },
            "maxItems": 5,
            "minItems": 1,
            "type": "array"
          }
        },
        "type": "object"
      },
      "Variant": {
        "properties": {
          "name": {
            "description": "The name of the variant. Must contain only alphanumeric characters, underscores, dashes, or plus symbols.",
            "example": "variant_A",
            "pattern": "^[a-zA-Z0-9_+-]+$",
            "type": "string"
          },
          "tags": {
            "description": "Tags to apply when this variant is selected. At least one tag is required.",
            "items": {
              "$ref": "#/components/schemas/Tag"
            },
            "minItems": 1,
            "type": "array"
          },
          "weight": {
            "description": "The weight of the variant. All variant weights must sum to 100.",
            "example": 50,
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          }
        },
        "required": [
          "name",
          "tags",
          "weight"
        ],
        "type": "object"
      }
    }
  }
}
```