> For the complete documentation index, see [llms.txt](https://docs.reflag.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.reflag.com/api/reflag-rest-api/reflag-api-reference.md).

# API Reference

Describes the Management API that allows clients to manage and update apps, flags, and related entities.

## List of applications

> Retrieve all accessible applications

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"orgId":{"type":"string","minLength":1,"description":"Organization identifier"},"appHeaderCollection":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/appHeader"},"description":"The individual items in the collection"}},"required":["data"],"additionalProperties":false,"description":"Collection of Basic app information"},"appHeader":{"type":"object","properties":{"org":{"$ref":"#/components/schemas/orgHeader"},"id":{"$ref":"#/components/schemas/appId"},"name":{"type":"string","description":"App name"},"demo":{"type":"boolean","description":"Whether the app is a demo app"},"flagKeyFormat":{"$ref":"#/components/schemas/flagKeyFormat"},"environments":{"type":"array","items":{"$ref":"#/components/schemas/environmentHeader"},"description":"Environments within the app"}},"required":["org","id","name","demo","flagKeyFormat","environments"],"additionalProperties":false,"description":"Basic app information"},"orgHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/orgId"},"name":{"type":"string","minLength":1,"description":"Organization name"}},"required":["id","name"],"additionalProperties":false,"description":"Organization's basic information"},"appId":{"type":"string","minLength":1,"description":"App identifier"},"flagKeyFormat":{"type":"string","enum":["custom","pascalCase","camelCase","snakeCaseUpper","snakeCaseLower","kebabCaseUpper","kebabCaseLower"],"description":"The enforced key format when creating flags"},"environmentHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/envId"},"name":{"type":"string","description":"Environment name"},"isProduction":{"type":"boolean","description":"Whether the environment is a production environment"},"order":{"type":"integer","minimum":0,"description":"Environment order in the app (zero-indexed)"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment version incremented when flag state changes"}},"required":["id","name","isProduction","order","flagStateVersion"],"additionalProperties":false,"description":"Basic environment information"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps":{"get":{"summary":"List of applications","description":"Retrieve all accessible applications","operationId":"listApps","parameters":[{"in":"query","name":"orgId","schema":{"$ref":"#/components/schemas/orgId"}}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/appHeaderCollection"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Get details of an application

> Retrieve a specific application by its identifier

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"app":{"type":"object","properties":{"org":{"$ref":"#/components/schemas/orgHeader"},"id":{"$ref":"#/components/schemas/appId"},"name":{"type":"string","description":"App name"},"demo":{"type":"boolean","description":"Whether the app is a demo app"},"flagKeyFormat":{"$ref":"#/components/schemas/flagKeyFormat"},"environments":{"type":"array","items":{"$ref":"#/components/schemas/environment"},"description":"Environments within the app"},"stages":{"type":"array","items":{"$ref":"#/components/schemas/stageHeader"},"description":"Stages within the app"},"segments":{"type":"array","items":{"$ref":"#/components/schemas/segmentHeader"},"description":"Segments within the app"}},"required":["org","id","name","demo","flagKeyFormat","environments","stages","segments"],"additionalProperties":false,"description":"App information with related collections"},"orgHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/orgId"},"name":{"type":"string","minLength":1,"description":"Organization name"}},"required":["id","name"],"additionalProperties":false,"description":"Organization's basic information"},"orgId":{"type":"string","minLength":1,"description":"Organization identifier"},"flagKeyFormat":{"type":"string","enum":["custom","pascalCase","camelCase","snakeCaseUpper","snakeCaseLower","kebabCaseUpper","kebabCaseLower"],"description":"The enforced key format when creating flags"},"environment":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/envId"},"name":{"type":"string","description":"Environment name"},"isProduction":{"type":"boolean","description":"Whether the environment is a production environment"},"order":{"type":"integer","minimum":0,"description":"Environment order in the app (zero-indexed)"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment version incremented when flag state changes"},"sdkAccess":{"type":"object","properties":{"publishableKey":{"type":"string","minLength":1,"maxLength":36,"description":"Publishable key"},"secretKey":{"type":"string","minLength":1,"maxLength":36,"description":"Secret key"}},"required":["publishableKey","secretKey"],"additionalProperties":false,"description":"SDK access details"}},"required":["id","name","isProduction","order","flagStateVersion","sdkAccess"],"additionalProperties":false,"description":"Environment details"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"stageHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/stageId"},"name":{"type":"string","minLength":1,"description":"Stage name"},"color":{"type":"string","minLength":1,"maxLength":64,"description":"Stage color (HTML color name or hex code)"},"order":{"type":"integer","minimum":0,"description":"Stage order"}},"required":["id","name","color","order"],"additionalProperties":false,"description":"Stage's basic information"},"stageId":{"type":"string","minLength":1,"description":"Stage identifier"},"segmentHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/segmentId"},"name":{"type":"string","minLength":1,"description":"Segment name"},"type":{"$ref":"#/components/schemas/segmentType"}},"required":["id","name","type"],"additionalProperties":false,"description":"Segment's basic information"},"segmentId":{"type":"string","minLength":1,"description":"Segment identifier"},"segmentType":{"type":"string","enum":["all","custom"],"description":"Segment type"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}":{"get":{"summary":"Get details of an application","description":"Retrieve a specific application by its identifier","operationId":"getApp","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/app"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## List flags for application

> Retrieve all flags for a specific application

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"flagHeaderCollection":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/flagHeader"},"description":"Page of the collection of flags"},"totalCount":{"type":"integer","description":"Total number of flags in collection"},"pageSize":{"type":"integer","description":"Page size"},"pageIndex":{"type":"integer","description":"Page index"},"sortBy":{"type":"string","enum":["name","key","stage","autoFeedbackSurveysEnabled","createdAt","rolledOutToEveryoneAt","environmentStatus","owner","lastCheck","lastTrack","stale","archivingChecks"],"description":"Sort by"},"sortOrder":{"description":"Sort order","$ref":"#/components/schemas/sortOrder"}},"required":["data","totalCount","pageSize","pageIndex","sortBy","sortOrder"],"additionalProperties":false,"description":"Collection response containing flags"},"flagHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"flagType":{"$ref":"#/components/schemas/flagType"},"description":{"description":"Flag description","type":"string"},"stage":{"$ref":"#/components/schemas/stageHeader"},"owner":{"$ref":"#/components/schemas/reflagUserHeader"},"archived":{"type":"boolean","description":"Whether the flag is archived"},"stale":{"type":"boolean","description":"Whether the flag is stale"},"permanent":{"type":"boolean","description":"Whether the flag is permanent"},"createdAt":{"description":"Timestamp when the flag was created","type":"string"},"rolledOutToEveryoneAt":{"description":"Timestamp when the flag was rolled out to everyone","type":"string"},"codeRefsCleanedUp":{"type":"boolean","description":"Whether code references for this flag have been cleaned up"},"codeRefsMarkedCleanUserName":{"description":"Name of the user who marked code references as cleaned up","type":"string"},"codeRefsMarkedCleanAt":{"description":"Timestamp when code references were marked as cleaned up","type":"string"},"lastCheckAt":{"description":"Timestamp when the flag was last checked","type":"string"},"noRecentChecks":{"type":"boolean","description":"Whether the flag has no recent access checks"},"lastTrackAt":{"description":"Timestamp when the flag was last tracked","type":"string"}},"required":["id","key","name","flagType","archived","stale","permanent","codeRefsCleanedUp","noRecentChecks"],"additionalProperties":false,"description":"Basic flag information"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"flagType":{"type":"string","enum":["boolean","multivariate"],"description":"The flag type: boolean (release) or multivariate"},"stageHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/stageId"},"name":{"type":"string","minLength":1,"description":"Stage name"},"color":{"type":"string","minLength":1,"maxLength":64,"description":"Stage color (HTML color name or hex code)"},"order":{"type":"integer","minimum":0,"description":"Stage order"}},"required":["id","name","color","order"],"additionalProperties":false,"description":"Stage's basic information"},"stageId":{"type":"string","minLength":1,"description":"Stage identifier"},"reflagUserHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/reflagUserId"},"name":{"type":"string","minLength":1,"description":"User's name"},"email":{"type":"string","format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$","description":"User's email"},"avatarUrl":{"description":"User's avatar URL","type":"string","format":"uri"}},"required":["id","name","email"],"additionalProperties":false,"description":"Reflag user's basic information"},"reflagUserId":{"type":"string","minLength":1,"description":"Reflag user identifier"},"sortOrder":{"default":"asc","description":"Sort order applied to the sorting column","type":"string","enum":["asc","desc"]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/flags":{"get":{"summary":"List flags for application","description":"Retrieve all flags for a specific application","operationId":"listFlags","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/flagHeaderCollection"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## List environments for application

> Retrieve all environments for a specific application

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"sortOrder":{"default":"asc","description":"Sort order applied to the sorting column","type":"string","enum":["asc","desc"]},"environmentHeaderSortByColumn":{"default":"order","description":"The column to sort by","type":"string","enum":["name","order"]},"environmentHeaderCollection":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/environmentHeader"},"description":"The individual items in the collection"},"sortOrder":{"$ref":"#/components/schemas/sortOrder"},"sortBy":{"$ref":"#/components/schemas/environmentHeaderSortByColumn"}},"required":["data","sortOrder","sortBy"],"additionalProperties":false,"description":"Collection of Basic environment information"},"environmentHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/envId"},"name":{"type":"string","description":"Environment name"},"isProduction":{"type":"boolean","description":"Whether the environment is a production environment"},"order":{"type":"integer","minimum":0,"description":"Environment order in the app (zero-indexed)"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment version incremented when flag state changes"}},"required":["id","name","isProduction","order","flagStateVersion"],"additionalProperties":false,"description":"Basic environment information"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/environments":{"get":{"summary":"List environments for application","description":"Retrieve all environments for a specific application","operationId":"listEnvironments","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"query","name":"sortOrder","schema":{"$ref":"#/components/schemas/sortOrder"},"description":"Sort order applied to the sorting column"},{"in":"query","name":"sortBy","schema":{"$ref":"#/components/schemas/environmentHeaderSortByColumn"},"description":"The column to sort by"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/environmentHeaderCollection"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Get environment details

> Retrieve details for a specific environment

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"environment":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/envId"},"name":{"type":"string","description":"Environment name"},"isProduction":{"type":"boolean","description":"Whether the environment is a production environment"},"order":{"type":"integer","minimum":0,"description":"Environment order in the app (zero-indexed)"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment version incremented when flag state changes"},"sdkAccess":{"type":"object","properties":{"publishableKey":{"type":"string","minLength":1,"maxLength":36,"description":"Publishable key"},"secretKey":{"type":"string","minLength":1,"maxLength":36,"description":"Secret key"}},"required":["publishableKey","secretKey"],"additionalProperties":false,"description":"SDK access details"}},"required":["id","name","isProduction","order","flagStateVersion","sdkAccess"],"additionalProperties":false,"description":"Environment details"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/environments/{envId}":{"get":{"summary":"Get environment details","description":"Retrieve details for a specific environment","operationId":"getEnvironment","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/environment"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Create a flag

> Create a new flag in the application. Returns the created flag and the resulting flag-state version for every environment.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"flagType":{"type":"string","enum":["boolean","multivariate"],"description":"The flag type: boolean (release) or multivariate"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"stageHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/stageId"},"name":{"type":"string","minLength":1,"description":"Stage name"},"color":{"type":"string","minLength":1,"maxLength":64,"description":"Stage color (HTML color name or hex code)"},"order":{"type":"integer","minimum":0,"description":"Stage order"}},"required":["id","name","color","order"],"additionalProperties":false,"description":"Stage's basic information"},"stageId":{"type":"string","minLength":1,"description":"Stage identifier"},"reflagUserHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/reflagUserId"},"name":{"type":"string","minLength":1,"description":"User's name"},"email":{"type":"string","format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$","description":"User's email"},"avatarUrl":{"description":"User's avatar URL","type":"string","format":"uri"}},"required":["id","name","email"],"additionalProperties":false,"description":"Reflag user's basic information"},"reflagUserId":{"type":"string","minLength":1,"description":"Reflag user identifier"},"appFlagStateVersions":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/flagStateVersion"},"description":"Current flag-state version keyed by environment ID"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment flag-state version containing the completed mutation"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/flags":{"post":{"summary":"Create a flag","description":"Create a new flag in the application. Returns the created flag and the resulting flag-state version for every environment.","operationId":"createFlag","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"key":{"type":"string","minLength":1,"description":"Key of the flag"},"flagType":{"default":"boolean","description":"Type of the flag","$ref":"#/components/schemas/flagType"},"name":{"type":"string","minLength":1,"description":"Name of the flag"},"description":{"description":"Description of the flag","anyOf":[{"type":"string","maxLength":8192},{"type":"null"}]},"stageId":{"description":"Stage ID of the flag","type":"string","minLength":14,"maxLength":14},"ownerUserId":{"type":["string","null"]},"permanent":{"default":false,"type":"boolean"},"secret":{"description":"Whether the flag is secret","type":"boolean"}},"required":["key","name"],"additionalProperties":false}}}},"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"flag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"flagType":{"$ref":"#/components/schemas/flagType"},"description":{"description":"Flag description","type":"string"},"stage":{"$ref":"#/components/schemas/stageHeader"},"owner":{"$ref":"#/components/schemas/reflagUserHeader"},"archived":{"type":"boolean","description":"Whether the flag is archived"},"stale":{"type":"boolean","description":"Whether the flag is stale"},"permanent":{"type":"boolean","description":"Whether the flag is permanent"},"createdAt":{"description":"Timestamp when the flag was created","type":"string"},"rolledOutToEveryoneAt":{"description":"Timestamp when the flag was rolled out to everyone","type":"string"},"codeRefsCleanedUp":{"type":"boolean","description":"Whether code references for this flag have been cleaned up"},"codeRefsMarkedCleanUserName":{"description":"Name of the user who marked code references as cleaned up","type":"string"},"codeRefsMarkedCleanAt":{"description":"Timestamp when code references were marked as cleaned up","type":"string"},"lastCheckAt":{"description":"Timestamp when the flag was last checked","type":"string"},"noRecentChecks":{"type":"boolean","description":"Whether the flag has no recent access checks"},"lastTrackAt":{"description":"Timestamp when the flag was last tracked","type":"string"},"parentFlagId":{"description":"Parent flag ID","type":"string"}},"required":["id","key","name","flagType","archived","stale","permanent","codeRefsCleanedUp","noRecentChecks"],"additionalProperties":false},"flagStateVersions":{"$ref":"#/components/schemas/appFlagStateVersions"}},"required":["flag","flagStateVersions"],"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Update a flag

> Update an existing flag. Returns the current flag-state version for every environment, including any versions advanced by this update.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"flagType":{"type":"string","enum":["boolean","multivariate"],"description":"The flag type: boolean (release) or multivariate"},"stageHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/stageId"},"name":{"type":"string","minLength":1,"description":"Stage name"},"color":{"type":"string","minLength":1,"maxLength":64,"description":"Stage color (HTML color name or hex code)"},"order":{"type":"integer","minimum":0,"description":"Stage order"}},"required":["id","name","color","order"],"additionalProperties":false,"description":"Stage's basic information"},"stageId":{"type":"string","minLength":1,"description":"Stage identifier"},"reflagUserHeader":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/reflagUserId"},"name":{"type":"string","minLength":1,"description":"User's name"},"email":{"type":"string","format":"email","pattern":"^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$","description":"User's email"},"avatarUrl":{"description":"User's avatar URL","type":"string","format":"uri"}},"required":["id","name","email"],"additionalProperties":false,"description":"Reflag user's basic information"},"reflagUserId":{"type":"string","minLength":1,"description":"Reflag user identifier"},"appFlagStateVersions":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/flagStateVersion"},"description":"Current flag-state version keyed by environment ID"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment flag-state version containing the completed mutation"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/flags/{flagId}":{"patch":{"summary":"Update a flag","description":"Update an existing flag. Returns the current flag-state version for every environment, including any versions advanced by this update.","operationId":"updateFlag","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"flagId","schema":{"$ref":"#/components/schemas/flagId"},"required":true,"description":"Flag ID"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","minLength":1,"description":"Name of the flag"},"description":{"description":"Description of the flag","anyOf":[{"type":"string","maxLength":8192},{"type":"null"}]},"ownerUserId":{"type":["string","null"]},"permanent":{"type":"boolean"},"secret":{"description":"Whether the flag is secret","type":"boolean"},"isArchived":{"type":"boolean"},"stageId":{"description":"Stage ID of the flag","type":"string","minLength":14,"maxLength":14}},"additionalProperties":false}}}},"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"type":"object","properties":{"flag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"flagType":{"$ref":"#/components/schemas/flagType"},"description":{"description":"Flag description","type":"string"},"stage":{"$ref":"#/components/schemas/stageHeader"},"owner":{"$ref":"#/components/schemas/reflagUserHeader"},"archived":{"type":"boolean","description":"Whether the flag is archived"},"stale":{"type":"boolean","description":"Whether the flag is stale"},"permanent":{"type":"boolean","description":"Whether the flag is permanent"},"createdAt":{"description":"Timestamp when the flag was created","type":"string"},"rolledOutToEveryoneAt":{"description":"Timestamp when the flag was rolled out to everyone","type":"string"},"codeRefsCleanedUp":{"type":"boolean","description":"Whether code references for this flag have been cleaned up"},"codeRefsMarkedCleanUserName":{"description":"Name of the user who marked code references as cleaned up","type":"string"},"codeRefsMarkedCleanAt":{"description":"Timestamp when code references were marked as cleaned up","type":"string"},"lastCheckAt":{"description":"Timestamp when the flag was last checked","type":"string"},"noRecentChecks":{"type":"boolean","description":"Whether the flag has no recent access checks"},"lastTrackAt":{"description":"Timestamp when the flag was last tracked","type":"string"},"parentFlagId":{"description":"Parent flag ID","type":"string"}},"required":["id","key","name","flagType","archived","stale","permanent","codeRefsCleanedUp","noRecentChecks"],"additionalProperties":false},"flagStateVersions":{"$ref":"#/components/schemas/appFlagStateVersions"}},"required":["flag","flagStateVersions"],"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Get flags for a company

> Retrieve flags evaluated with current runtime rules and the company's stored attributes. value is the evaluated enabled state, not a default or the last SDK result. specificTargetValue is saved assignment metadata and can remain true while No one makes value false. No user or other/request context is supplied; stored attributes may differ from a live SDK request.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"companyId":{"type":"string","minLength":1,"maxLength":128,"description":"Company ID within your application"},"entityFlagsResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/entityFlag"},"description":"List of flags with their enabled status"},"totalCount":{"type":"integer","description":"Total number of flags"},"pageSize":{"type":"integer","description":"Page size"},"pageIndex":{"type":"integer","description":"Page index"}},"required":["data","totalCount","pageSize","pageIndex"],"additionalProperties":false,"description":"Response containing flags for an entity"},"entityFlag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"createdAt":{"type":"string","description":"Timestamp when the flag was created"},"value":{"type":"boolean","description":"Evaluated enabled state using current runtime rules and stored entity attributes, not the last SDK result or a default value. Company checks supply only company context. User checks supply user context and also check each stored company membership; no other/request context is supplied. Stored attributes and context may differ from a live SDK request."},"specificTargetValue":{"description":"Saved explicit assignment, or null if absent. May be true while value is false when targeting is No one. This is configuration metadata, not an effective-access override.","type":["boolean","null"]},"firstExposureAt":{"description":"First time the entity was exposed to this flag","type":["string","null"]},"lastExposureAt":{"description":"Last time the entity was exposed to this flag","type":["string","null"]},"lastCheckAt":{"description":"Last time the flag was checked for this entity","type":["string","null"]},"exposureCount":{"type":"integer","description":"Number of times the entity was exposed to this flag"},"firstTrackAt":{"description":"First time a track event was recorded for this flag","type":["string","null"]},"lastTrackAt":{"description":"Last time a track event was recorded for this flag","type":["string","null"]},"trackCount":{"type":"integer","description":"Number of track events for this flag"}},"required":["id","key","name","createdAt","value","specificTargetValue","firstExposureAt","lastExposureAt","lastCheckAt","exposureCount","firstTrackAt","lastTrackAt","trackCount"],"additionalProperties":false,"description":"Flag information with enabled status for an entity"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/companies/{companyId}/flags":{"get":{"summary":"Get flags for a company","description":"Retrieve flags evaluated with current runtime rules and the company's stored attributes. value is the evaluated enabled state, not a default or the last SDK result. specificTargetValue is saved assignment metadata and can remain true while No one makes value false. No user or other/request context is supplied; stored attributes may differ from a live SDK request.","operationId":"getCompanyFlags","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"companyId","schema":{"$ref":"#/components/schemas/companyId"},"required":true,"description":"Company ID within your application"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/entityFlagsResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Update flag targeting for a company

> Update specific targeting for flags for a company in an environment. Returns the environment flag-state version containing the completed update.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"companyId":{"type":"string","minLength":1,"maxLength":128,"description":"Company ID within your application"},"updateEntityFlagsBody":{"type":"object","properties":{"updates":{"minItems":1,"type":"array","items":{"$ref":"#/components/schemas/entityFlagUpdate"},"description":"List of flag updates to apply"},"changeDescription":{"description":"Description of the change for audit history","type":"string"},"notifications":{"description":"Destination list for notifications about the change. Use [] to disable notifications. Omit to use configured defaults.","type":"array","items":{"type":"string","enum":["linearComment","slack"]}}},"required":["updates"],"description":"Request body for updating flags for an entity"},"entityFlagUpdate":{"type":"object","properties":{"flagKey":{"$ref":"#/components/schemas/flagKey"},"specificTargetValue":{"anyOf":[{"type":"boolean","const":true},{"type":"null"}],"description":"Set to true to add a specific-targeting override, or null to remove it"}},"required":["flagKey","specificTargetValue"],"description":"Update for a single flag's explicit targeting override"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"updateEntityFlagsResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/entityFlag"},"description":"List of flags with their enabled status"},"totalCount":{"type":"integer","description":"Total number of flags"},"pageSize":{"type":"integer","description":"Page size"},"pageIndex":{"type":"integer","description":"Page index"},"flagStateVersion":{"$ref":"#/components/schemas/flagStateVersion"}},"required":["data","totalCount","pageSize","pageIndex","flagStateVersion"],"additionalProperties":false,"description":"Updated entity flags and the environment flag-state version containing the change"},"entityFlag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"createdAt":{"type":"string","description":"Timestamp when the flag was created"},"value":{"type":"boolean","description":"Evaluated enabled state using current runtime rules and stored entity attributes, not the last SDK result or a default value. Company checks supply only company context. User checks supply user context and also check each stored company membership; no other/request context is supplied. Stored attributes and context may differ from a live SDK request."},"specificTargetValue":{"description":"Saved explicit assignment, or null if absent. May be true while value is false when targeting is No one. This is configuration metadata, not an effective-access override.","type":["boolean","null"]},"firstExposureAt":{"description":"First time the entity was exposed to this flag","type":["string","null"]},"lastExposureAt":{"description":"Last time the entity was exposed to this flag","type":["string","null"]},"lastCheckAt":{"description":"Last time the flag was checked for this entity","type":["string","null"]},"exposureCount":{"type":"integer","description":"Number of times the entity was exposed to this flag"},"firstTrackAt":{"description":"First time a track event was recorded for this flag","type":["string","null"]},"lastTrackAt":{"description":"Last time a track event was recorded for this flag","type":["string","null"]},"trackCount":{"type":"integer","description":"Number of track events for this flag"}},"required":["id","key","name","createdAt","value","specificTargetValue","firstExposureAt","lastExposureAt","lastCheckAt","exposureCount","firstTrackAt","lastTrackAt","trackCount"],"additionalProperties":false,"description":"Flag information with enabled status for an entity"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment flag-state version containing the completed mutation"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/companies/{companyId}/flags":{"patch":{"summary":"Update flag targeting for a company","description":"Update specific targeting for flags for a company in an environment. Returns the environment flag-state version containing the completed update.","operationId":"updateCompanyFlags","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"companyId","schema":{"$ref":"#/components/schemas/companyId"},"required":true,"description":"Company ID within your application"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/updateEntityFlagsBody"}}}},"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/updateEntityFlagsResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Get flags for a user

> Retrieve flags evaluated with current runtime rules and stored user attributes, also checking each stored company membership separately. value is the evaluated enabled state, not a default or the last SDK result. specificTargetValue is saved assignment metadata and can remain true while No one makes value false. No other/request context is supplied; this is not a replay of a single live SDK request.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"userId":{"type":"string","minLength":1,"maxLength":128,"description":"User ID within your application"},"entityFlagsResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/entityFlag"},"description":"List of flags with their enabled status"},"totalCount":{"type":"integer","description":"Total number of flags"},"pageSize":{"type":"integer","description":"Page size"},"pageIndex":{"type":"integer","description":"Page index"}},"required":["data","totalCount","pageSize","pageIndex"],"additionalProperties":false,"description":"Response containing flags for an entity"},"entityFlag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"createdAt":{"type":"string","description":"Timestamp when the flag was created"},"value":{"type":"boolean","description":"Evaluated enabled state using current runtime rules and stored entity attributes, not the last SDK result or a default value. Company checks supply only company context. User checks supply user context and also check each stored company membership; no other/request context is supplied. Stored attributes and context may differ from a live SDK request."},"specificTargetValue":{"description":"Saved explicit assignment, or null if absent. May be true while value is false when targeting is No one. This is configuration metadata, not an effective-access override.","type":["boolean","null"]},"firstExposureAt":{"description":"First time the entity was exposed to this flag","type":["string","null"]},"lastExposureAt":{"description":"Last time the entity was exposed to this flag","type":["string","null"]},"lastCheckAt":{"description":"Last time the flag was checked for this entity","type":["string","null"]},"exposureCount":{"type":"integer","description":"Number of times the entity was exposed to this flag"},"firstTrackAt":{"description":"First time a track event was recorded for this flag","type":["string","null"]},"lastTrackAt":{"description":"Last time a track event was recorded for this flag","type":["string","null"]},"trackCount":{"type":"integer","description":"Number of track events for this flag"}},"required":["id","key","name","createdAt","value","specificTargetValue","firstExposureAt","lastExposureAt","lastCheckAt","exposureCount","firstTrackAt","lastTrackAt","trackCount"],"additionalProperties":false,"description":"Flag information with enabled status for an entity"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/users/{userId}/flags":{"get":{"summary":"Get flags for a user","description":"Retrieve flags evaluated with current runtime rules and stored user attributes, also checking each stored company membership separately. value is the evaluated enabled state, not a default or the last SDK result. specificTargetValue is saved assignment metadata and can remain true while No one makes value false. No other/request context is supplied; this is not a replay of a single live SDK request.","operationId":"getUserFlags","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"userId","schema":{"$ref":"#/components/schemas/userId"},"required":true,"description":"User ID within your application"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/entityFlagsResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Update flag targeting for a user

> Update specific targeting for flags for a user in an environment. Returns the environment flag-state version containing the completed update.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"userId":{"type":"string","minLength":1,"maxLength":128,"description":"User ID within your application"},"updateEntityFlagsBody":{"type":"object","properties":{"updates":{"minItems":1,"type":"array","items":{"$ref":"#/components/schemas/entityFlagUpdate"},"description":"List of flag updates to apply"},"changeDescription":{"description":"Description of the change for audit history","type":"string"},"notifications":{"description":"Destination list for notifications about the change. Use [] to disable notifications. Omit to use configured defaults.","type":"array","items":{"type":"string","enum":["linearComment","slack"]}}},"required":["updates"],"description":"Request body for updating flags for an entity"},"entityFlagUpdate":{"type":"object","properties":{"flagKey":{"$ref":"#/components/schemas/flagKey"},"specificTargetValue":{"anyOf":[{"type":"boolean","const":true},{"type":"null"}],"description":"Set to true to add a specific-targeting override, or null to remove it"}},"required":["flagKey","specificTargetValue"],"description":"Update for a single flag's explicit targeting override"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"updateEntityFlagsResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/entityFlag"},"description":"List of flags with their enabled status"},"totalCount":{"type":"integer","description":"Total number of flags"},"pageSize":{"type":"integer","description":"Page size"},"pageIndex":{"type":"integer","description":"Page index"},"flagStateVersion":{"$ref":"#/components/schemas/flagStateVersion"}},"required":["data","totalCount","pageSize","pageIndex","flagStateVersion"],"additionalProperties":false,"description":"Updated entity flags and the environment flag-state version containing the change"},"entityFlag":{"type":"object","properties":{"id":{"$ref":"#/components/schemas/flagId"},"key":{"$ref":"#/components/schemas/flagKey"},"name":{"type":"string","minLength":1,"maxLength":255,"description":"Flag name"},"createdAt":{"type":"string","description":"Timestamp when the flag was created"},"value":{"type":"boolean","description":"Evaluated enabled state using current runtime rules and stored entity attributes, not the last SDK result or a default value. Company checks supply only company context. User checks supply user context and also check each stored company membership; no other/request context is supplied. Stored attributes and context may differ from a live SDK request."},"specificTargetValue":{"description":"Saved explicit assignment, or null if absent. May be true while value is false when targeting is No one. This is configuration metadata, not an effective-access override.","type":["boolean","null"]},"firstExposureAt":{"description":"First time the entity was exposed to this flag","type":["string","null"]},"lastExposureAt":{"description":"Last time the entity was exposed to this flag","type":["string","null"]},"lastCheckAt":{"description":"Last time the flag was checked for this entity","type":["string","null"]},"exposureCount":{"type":"integer","description":"Number of times the entity was exposed to this flag"},"firstTrackAt":{"description":"First time a track event was recorded for this flag","type":["string","null"]},"lastTrackAt":{"description":"Last time a track event was recorded for this flag","type":["string","null"]},"trackCount":{"type":"integer","description":"Number of track events for this flag"}},"required":["id","key","name","createdAt","value","specificTargetValue","firstExposureAt","lastExposureAt","lastCheckAt","exposureCount","firstTrackAt","lastTrackAt","trackCount"],"additionalProperties":false,"description":"Flag information with enabled status for an entity"},"flagId":{"type":"string","minLength":1,"description":"Flag ID"},"flagStateVersion":{"type":"integer","minimum":0,"description":"Environment flag-state version containing the completed mutation"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/users/{userId}/flags":{"patch":{"summary":"Update flag targeting for a user","description":"Update specific targeting for flags for a user in an environment. Returns the environment flag-state version containing the completed update.","operationId":"updateUserFlags","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"userId","schema":{"$ref":"#/components/schemas/userId"},"required":true,"description":"User ID within your application"}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/updateEntityFlagsBody"}}}},"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/updateEntityFlagsResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Get flag targeting for an environment

> Read a flag's authored targeting mode, saved explicit assignments, and compiled runtime enable rules with read scope. Saved targets may remain configured while No one disables all effective rules. Version, mode, assignments, and effective rules come from one configuration snapshot. This does not guarantee SDK propagation or replay a live evaluation context.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"flagKey":{"type":"string","minLength":1,"description":"Unique flag key"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"flagTargeting":{"type":"object","properties":{"flagKey":{"$ref":"#/components/schemas/flagKey"},"version":{"$ref":"#/components/schemas/flagVersion"},"targetingMode":{"type":"string","enum":["none","some","everyone"],"description":"Authored targeting mode. Saved specific targets are inactive when this is none and are not required when it is everyone."},"effectiveRules":{"type":"array","items":{"$ref":"#/components/schemas/effectiveFlagRule"},"description":"Compiled runtime enable rules, including active opt-ins, with segment and flag references resolved. Rules are evaluated independently (OR), not as one combined rule. Empty for No one, archived flags, or a configuration with no enable rules. Uses the same authored snapshot as version; does not guarantee SDK propagation or reproduce a live SDK context."},"updatedAt":{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$","description":"Last time the targeting was updated"},"specificTargets":{"type":"object","propertyNames":{"$ref":"#/components/schemas/flagValue"},"additionalProperties":{"$ref":"#/components/schemas/flagValueTargeting"},"required":["true"],"description":"Saved explicit assignments, preserved even when inactive. Use targetingMode and effectiveRules to interpret effective targeting, not list membership alone."}},"required":["flagKey","version","targetingMode","effectiveRules","updatedAt","specificTargets"],"additionalProperties":false,"description":"Flag targeting information and its audience"},"flagVersion":{"type":"integer","description":"Flag targeting version"},"effectiveFlagRule":{"type":"object","properties":{"filter":{"$ref":"#/components/schemas/effectiveFlagFilter"}},"required":["filter"],"additionalProperties":false,"description":"One independent enable rule; a flag is enabled if any rule matches"},"effectiveFlagFilter":{"description":"A compiled runtime filter with segment and flag references resolved","anyOf":[{"type":"object","properties":{"type":{"type":"string","const":"context"},"field":{"type":"string"},"operator":{"type":"string","enum":["IS","IS_NOT","ANY_OF","NOT_ANY_OF","CONTAINS","NOT_CONTAINS","GT","LT","AFTER","BEFORE","DATE_AFTER","DATE_BEFORE","SET","NOT_SET","IS_TRUE","IS_FALSE"]},"values":{"type":"array","items":{"type":"string"}}},"required":["type","field","operator"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","const":"rolloutPercentage"},"key":{"type":"string"},"partialRolloutAttribute":{"type":"string"},"partialRolloutThreshold":{"type":"integer"}},"required":["type","key","partialRolloutAttribute","partialRolloutThreshold"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","const":"constant"},"value":{"type":"boolean"}},"required":["type","value"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","const":"group"},"operator":{"type":"string","enum":["and","or"]},"filters":{"type":"array","items":{"$ref":"#/components/schemas/effectiveFlagFilter"}}},"required":["type","operator","filters"],"additionalProperties":false},{"type":"object","properties":{"type":{"type":"string","const":"negation"},"filter":{"$ref":"#/components/schemas/effectiveFlagFilter"}},"required":["type","filter"],"additionalProperties":false}]},"flagValue":{"type":"string","const":"true","description":"The saved explicit value for the audience; does not imply that targeting is active."},"flagValueTargeting":{"type":"object","properties":{"companyIds":{"type":"array","items":{"$ref":"#/components/schemas/companyId"},"description":"Companies that were explicitly given the value"},"userIds":{"type":"array","items":{"$ref":"#/components/schemas/userId"},"description":"Users that were explicitly given the value"}},"required":["companyIds","userIds"],"additionalProperties":false,"description":"Flag targeting value and its audience"},"companyId":{"type":"string","minLength":1,"maxLength":128,"description":"Company ID within your application"},"userId":{"type":"string","minLength":1,"maxLength":128,"description":"User ID within your application"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/flags/{flagKey}/targeting/{envId}":{"get":{"summary":"Get flag targeting for an environment","description":"Read a flag's authored targeting mode, saved explicit assignments, and compiled runtime enable rules with read scope. Saved targets may remain configured while No one disables all effective rules. Version, mode, assignments, and effective rules come from one configuration snapshot. This does not guarantee SDK propagation or replay a live evaluation context.","operationId":"getFlagTargeting","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"flagKey","schema":{"$ref":"#/components/schemas/flagKey"},"required":true,"description":"Unique flag key"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"}],"responses":{"200":{"description":"Requested resource retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/flagTargeting"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Create or update a company

> Synchronously create or update a company in an environment. Requires the \`write:entities\` API key scope or admin member access. This scope also grants deletion through the corresponding entity DELETE endpoints, but does not grant membership changes or flag targeting; grant \`write:flag:targeting\` separately to assign flags and \`read\` for GET requests. Attributes accept JSON values and are normalized and merged using the same rules as ingestion. Recognized name and avatar attributes also update the corresponding company fields; top-level \`name\` takes precedence over name attributes. Omitting a field preserves its existing value. New companies may omit all fields. When this request succeeds, a subsequent company targeting request can read the company. Flag configuration propagation to SDKs is independent. Delayed ingestion writes may later replace overlapping values because the last database writer wins.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"companyId":{"type":"string","minLength":1,"maxLength":128,"description":"Company ID within your application"},"entityAttributesInput":{"anyOf":[{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema0"}},{"type":"null"}],"description":"Entity attributes. Values are normalized exactly like ingestion before being merged with existing attributes."},"__schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"type":"array","items":{"$ref":"#/components/schemas/__schema0"}},{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema0"}}]},"entityAttributesInputOutput":{"anyOf":[{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema1"}},{"type":"null"}],"description":"Entity attributes. Values are normalized exactly like ingestion before being merged with existing attributes."},"__schema1":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"type":"array","items":{"$ref":"#/components/schemas/__schema1"}},{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema1"}}]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/companies/{companyId}":{"put":{"summary":"Create or update a company","description":"Synchronously create or update a company in an environment. Requires the `write:entities` API key scope or admin member access. This scope also grants deletion through the corresponding entity DELETE endpoints, but does not grant membership changes or flag targeting; grant `write:flag:targeting` separately to assign flags and `read` for GET requests. Attributes accept JSON values and are normalized and merged using the same rules as ingestion. Recognized name and avatar attributes also update the corresponding company fields; top-level `name` takes precedence over name attributes. Omitting a field preserves its existing value. New companies may omit all fields. When this request succeeds, a subsequent company targeting request can read the company. Flag configuration propagation to SDKs is independent. Delayed ingestion writes may later replace overlapping values because the last database writer wins.","operationId":"upsertCompany","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"companyId","schema":{"$ref":"#/components/schemas/companyId"},"required":true,"description":"Company ID within your application"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"Company name. Omit it to preserve an existing name; new companies may be unnamed.","type":"string","minLength":1,"maxLength":128},"attributes":{"$ref":"#/components/schemas/entityAttributesInput"}},"additionalProperties":false}}}},"responses":{"200":{"description":"Company created or updated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"Company name. Omit it to preserve an existing name; new companies may be unnamed.","type":"string","minLength":1,"maxLength":128},"attributes":{"$ref":"#/components/schemas/entityAttributesInputOutput"},"id":{"$ref":"#/components/schemas/companyId"}},"required":["id"],"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Delete a company

> Synchronously delete a company and its related data from an environment. Requires the \`write:entities\` API key scope or admin member access. By default, users that belong only to this company are also deleted; set \`deleteUsers\` to false to preserve them. Users that belong to other companies are always preserved.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"companyId":{"type":"string","minLength":1,"maxLength":128,"description":"Company ID within your application"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/companies/{companyId}":{"delete":{"summary":"Delete a company","description":"Synchronously delete a company and its related data from an environment. Requires the `write:entities` API key scope or admin member access. By default, users that belong only to this company are also deleted; set `deleteUsers` to false to preserve them. Users that belong to other companies are always preserved.","operationId":"deleteCompany","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"companyId","schema":{"$ref":"#/components/schemas/companyId"},"required":true,"description":"Company ID within your application"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"deleteUsers":{"type":"boolean"}}}}}},"responses":{"200":{"description":"Company deleted successfully","content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Create or update a user

> Synchronously create or update a user in an environment. Requires the \`write:entities\` API key scope or admin member access. This scope also grants deletion through the corresponding entity DELETE endpoints, but does not grant membership changes or flag targeting; grant \`write:flag:targeting\` separately to assign flags and \`read\` for GET requests. Attributes accept JSON values and are normalized and merged using the same rules as ingestion. Recognized name, email, and avatar attributes also update the corresponding user fields; top-level \`name\` takes precedence over name attributes. Omitting a field preserves its existing value. New users may omit all fields. When this request succeeds, a subsequent user targeting request can read the user. Flag configuration propagation to SDKs is independent. Delayed ingestion writes may later replace overlapping values because the last database writer wins.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"userId":{"type":"string","minLength":1,"maxLength":128,"description":"User ID within your application"},"entityAttributesInput":{"anyOf":[{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema0"}},{"type":"null"}],"description":"Entity attributes. Values are normalized exactly like ingestion before being merged with existing attributes."},"__schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"type":"array","items":{"$ref":"#/components/schemas/__schema0"}},{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema0"}}]},"entityAttributesInputOutput":{"anyOf":[{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema1"}},{"type":"null"}],"description":"Entity attributes. Values are normalized exactly like ingestion before being merged with existing attributes."},"__schema1":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"type":"array","items":{"$ref":"#/components/schemas/__schema1"}},{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"$ref":"#/components/schemas/__schema1"}}]},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/users/{userId}":{"put":{"summary":"Create or update a user","description":"Synchronously create or update a user in an environment. Requires the `write:entities` API key scope or admin member access. This scope also grants deletion through the corresponding entity DELETE endpoints, but does not grant membership changes or flag targeting; grant `write:flag:targeting` separately to assign flags and `read` for GET requests. Attributes accept JSON values and are normalized and merged using the same rules as ingestion. Recognized name, email, and avatar attributes also update the corresponding user fields; top-level `name` takes precedence over name attributes. Omitting a field preserves its existing value. New users may omit all fields. When this request succeeds, a subsequent user targeting request can read the user. Flag configuration propagation to SDKs is independent. Delayed ingestion writes may later replace overlapping values because the last database writer wins.","operationId":"upsertUser","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"userId","schema":{"$ref":"#/components/schemas/userId"},"required":true,"description":"User ID within your application"}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"User name. Omit it to preserve an existing name; new users may be unnamed.","type":"string","minLength":1,"maxLength":128},"attributes":{"$ref":"#/components/schemas/entityAttributesInput"}},"additionalProperties":false}}}},"responses":{"200":{"description":"User created or updated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"User name. Omit it to preserve an existing name; new users may be unnamed.","type":"string","minLength":1,"maxLength":128},"attributes":{"$ref":"#/components/schemas/entityAttributesInputOutput"},"id":{"$ref":"#/components/schemas/userId"}},"required":["id"],"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Delete a user

> Synchronously delete a user and its related data, including company memberships, from an environment. Requires the \`write:entities\` API key scope or admin member access.

```json
{"openapi":"3.1.0","info":{"title":"Reflag Management API","version":"3.1.0"},"servers":[{"url":"https://app.reflag.com/api","description":"Production server"}],"security":[{"APIKey":[]}],"components":{"securitySchemes":{"APIKey":{"type":"http","scheme":"bearer","description":"API key authentication, for service access"}},"schemas":{"appId":{"type":"string","minLength":1,"description":"App identifier"},"envId":{"type":"string","minLength":1,"description":"Environment identifier"},"userId":{"type":"string","minLength":1,"maxLength":128,"description":"User ID within your application"},"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","not_found","not_possible","not_allowed","not_available","unknown_error","unauthorized","unauthenticated"],"description":"Error code"},"message":{"type":"string","description":"Human readable error message"}},"required":["code","message"],"additionalProperties":false,"description":"The error"},"issues":{"description":"Individual validation issues, if applicable","type":"object","propertyNames":{"type":"string","description":"The field that has the issue (uses dot notation). Empty string if the issue is at the root."},"additionalProperties":{"type":"array","items":{"type":"string","description":"The error message"},"description":"Error messages for this field"}}},"required":["error"],"additionalProperties":false,"description":"The error response, including individual issues, if applicable"}}},"paths":{"/apps/{appId}/envs/{envId}/users/{userId}":{"delete":{"summary":"Delete a user","description":"Synchronously delete a user and its related data, including company memberships, from an environment. Requires the `write:entities` API key scope or admin member access.","operationId":"deleteUser","parameters":[{"in":"path","name":"appId","schema":{"$ref":"#/components/schemas/appId"},"required":true,"description":"App identifier"},{"in":"path","name":"envId","schema":{"$ref":"#/components/schemas/envId"},"required":true,"description":"Environment identifier"},{"in":"path","name":"userId","schema":{"$ref":"#/components/schemas/userId"},"required":true,"description":"User ID within your application"}],"responses":{"200":{"description":"User deleted successfully","content":{"application/json":{"schema":{"type":"object","properties":{},"additionalProperties":false}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Requested resource, or its parent, not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.reflag.com/api/reflag-rest-api/reflag-api-reference.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
