सामग्री पर जाएं

Feature Flags API

यह सामग्री अभी तक आपकी भाषा में उपलब्ध नहीं है।

A feature flag is a remote switch with properties that the SDK reads for each device. This API manages the flags of an application: the same operations as Audience → Feature Flags in the Control Panel. To read flags on a website, use the Web SDK.

https://rpc-api.svc-nue.pushwoosh.com

All endpoints are served over HTTPS. Requests and responses use application/json.

Authentication

Anchor link to

Every request must include an Authorization header with your Server API token:

Authorization: Api YOUR_API_TOKEN

Reading flags needs access to the application. Creating and changing them needs the right to manage it.

Conventions

Anchor link to
  • Field naming: request bodies accept lowerCamelCase or snake_case. Responses use snake_case, as in the Feature flag object.
  • Percentages are in basis points: percent_bp from 0 to 10000, where 2000 is 20%.
  • Versions: every flag carries a version. Update, SetRulePercent, and Reshuffle take the version you last read and fail with VERSION_CONFLICT when the flag changed since, so concurrent edits never overwrite each other. Read the flag again and retry.
  • Statuses: active, killed, or archived. Kill, Unkill, Archive, and Restore change only the status and take no version.

Each REST endpoint has an MCP tool with the same parameters:

MethodPathDescriptionMCP tool
GET/api/applications/{application_code}/feature_flagsList the application’s flagslist_feature_flags
GET/api/applications/{application_code}/feature_flags/{key}Get one flagget_feature_flag
POST/api/applications/{application_code}/feature_flagsCreate a flagcreate_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}Replace name, description, properties, and rulesupdate_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}/rules/{rule_id}/percentChange the rollout of one ruleset_feature_flag_rule_percent
POST/api/applications/{application_code}/feature_flags/{key}/killTurn the flag off for everyonekill_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}/unkillTurn a killed flag back onunkill_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}/archiveArchive a flagarchive_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}/restoreRestore an archived flagrestore_feature_flag
POST/api/applications/{application_code}/feature_flags/{key}/reshufflePick a new sample of usersreshuffle_feature_flag

Every endpoint except List returns { "flag": { ... } }, the Feature flag object after the operation.

GET /api/applications/{application_code}/feature_flags

The request takes these parameters:

ParameterInTypeDescription
application_codepathstringThe application code.
statusquerystringOptional. active, killed, or archived. Omit to list all flags.

Returns { "flags": [ ... ] }, an array of Feature flag objects.

GET /api/applications/{application_code}/feature_flags/{key}

Returns one flag with its properties, rules, and current version.

Creates an active flag. The server generates the rule_id of every rule.

POST /api/applications/{application_code}/feature_flags

The request body has these fields:

ParameterTypeRequiredDescription
keystringYesMatches ^[A-Za-z0-9_.-]{1,58}$. Unique in the application, archived flags included, compared case-insensitively. Can’t be changed later.
namestringNoDisplay name, up to 255 characters.
descriptionstringNoDescription.
propertiesarray of Property objectsNoUp to 50 properties.
defaultsobjectYes, if there are propertiesThe value of every property for devices the flag is off for, keyed by property key. Each value must match the property type.
rulesarray of Rule objectsNoOrdered rules, up to 10. The first rule whose segment matches the device decides.
Request example
Anchor link to
{
"key": "new_checkout",
"name": "New checkout",
"properties": [
{ "key": "button_color", "type": "string" },
{ "key": "show_apple_pay", "type": "boolean" }
],
"defaults": { "button_color": "blue", "show_apple_pay": false },
"rules": [
{
"name": "Beta testers",
"filter_code": "XXXXX-XXXXX",
"percent_bp": 10000,
"overrides": { "button_color": "green", "show_apple_pay": true }
},
{
"name": "Everyone else",
"filter_code": "",
"percent_bp": 2000,
"overrides": { "button_color": "orange" }
}
]
}

Replaces the name, description, properties, defaults, and rules of a flag. The status never changes here. Send all fields, not only the changed ones.

POST /api/applications/{application_code}/feature_flags/{key}

Takes the same body as Create without key, plus version from your last read. Keep the rule_id of every existing rule. A rule without rule_id is created as new. A property’s type can’t change after the property is created.

SetRulePercent

Anchor link to

Changes the rollout of one rule. Users who already have the flag keep it when the percentage grows.

POST /api/applications/{application_code}/feature_flags/{key}/rules/{rule_id}/percent

{ "percentBp": 5000, "version": 3 }

Kill and Unkill

Anchor link to

POST .../feature_flags/{key}/kill turns the flag off for every device, which then gets the default property values. Rules and properties are kept.

POST .../feature_flags/{key}/unkill turns a killed flag back on with its rules as they were.

Both take an empty body {}.

Archive and Restore

Anchor link to

POST .../feature_flags/{key}/archive stops sending the flag to devices. An archived flag doesn’t count toward the plan’s limit of flags per application, and its key stays reserved.

POST .../feature_flags/{key}/restore brings an archived flag back as killed, so it never turns on by itself. Call unkill to roll it out again.

Both take an empty body {}.

Places every user in a new bucket, so the same percentages select a different sample of users. Some users who have the flag on lose it, and others get it.

POST /api/applications/{application_code}/feature_flags/{key}/reshuffle

{ "confirm": true, "version": 3 }

confirm must be true. Otherwise the request fails with CONFIRM_REQUIRED.

Feature flag object

Anchor link to

Every endpoint returns the flag in this shape:

FieldTypeDescription
application_codestringThe application the flag belongs to.
keystringThe flag key.
namestringDisplay name.
descriptionstringDescription.
statusstringactive, killed, or archived.
propertiesarray of Property objectsThe flag’s properties.
defaultsobjectThe value of every property for devices the flag is off for.
rulesarray of Rule objectsOrdered rules.
versionintegerSend it back with Update, SetRulePercent, and Reshuffle.
createdstringCreation time, RFC 3339.
updatedstringLast change time, RFC 3339.
last_modified_by_user_idstringThe Control Panel user who changed the flag last.

Property object

Anchor link to

A property describes one value the SDK reads from the flag:

FieldTypeDescription
keystringMatches ^[A-Za-z0-9_]{1,64}$, unique within the flag.
typestringstring, number, boolean, or json. Can’t change once the property exists.

Rule object

Anchor link to

A rule decides who gets the flag on and with which values:

FieldTypeDescription
rule_idstringGenerated by the server, r_ followed by 8 hex digits, and stable across updates. Leave it empty for a new rule.
namestringRule name.
filter_codestringThe segment the device must match. Empty matches every device. The segment can hold only tag, location, application, and list conditions.
percent_bpintegerShare of matching users the flag is on for, 0–10000. A device that matches the segment stops at this rule even when it falls outside the percentage.
overridesobjectProperty values that replace the defaults for devices this rule turns on, keyed by property key.

A rejected request returns one of these HTTP status codes:

HTTP statusMeaning
400 Bad RequestThe request is invalid (field_violations) or the flag’s state or the plan doesn’t allow it (Type). See the body formats and reasons below.
401 UnauthorizedThe Authorization header is missing or the token is invalid.
403 ForbiddenThe token can’t manage the application, or the application is a system one.
404 Not FoundThe application or the flag doesn’t exist.
409 ConflictAnother request is changing the same flag at this moment. Retry the request.
500 Internal Server ErrorUnexpected server failure. The body is {"message": "Sorry, an unexpected error occurred"}.

An invalid request returns 400 with a list of field violations. Each violation names the field, the reason, and the arguments of the reason:

{
"code": 3,
"message": "validation failed",
"details": [
{
"@type": "type.googleapis.com/pushwoosh.rpc.errors.v3.BadRequest",
"field_violations": [
{
"field": "key",
"description": "a feature flag with this key already exists in the application",
"reason": "KEY_TAKEN",
"args": { "key": "new_checkout" }
}
]
}
]
}

A request that the flag’s state or the plan doesn’t allow returns 400 with one failed precondition. Its Type and Description fields are capitalized:

{
"code": 9,
"message": "precondition failed",
"details": [
{
"@type": "type.googleapis.com/pushwoosh.rpc.errors.v3.FailedPrecondition",
"Type": "VERSION_CONFLICT",
"Description": "feature flag was changed: version 3 was sent, the current one is 4"
}
]
}

The reason of a field violation and the Type of a failed precondition take these values:

ReasonCause
KEY_INVALIDThe key doesn’t match ^[A-Za-z0-9_.-]{1,58}$.
KEY_TAKENAnother flag of the application, archived ones included, has this key.
TEXT_INVALIDThe name or description is too long or has forbidden characters.
PROPERTIES_LIMITMore than 50 properties.
PROPERTY_KEY_INVALIDA property key is invalid or repeated.
PROPERTY_TYPE_INVALIDA property type isn’t string, number, boolean, or json.
PROPERTY_TYPE_IMMUTABLEThe request changes the type of an existing property.
VALUE_INVALIDA default or override is missing, doesn’t match the property type, or is nested deeper than 5 levels.
PROPERTIES_TOO_LARGEThe property values of the flag exceed 10,000 bytes.
RULES_LIMITMore than 10 rules.
RULE_NOT_FOUNDThe rule_id isn’t one of the flag’s rules.
PERCENT_INVALIDpercent_bp is outside 0–10000.
OVERRIDE_UNKNOWN_PROPERTYAn override names a property the flag doesn’t have.
SEGMENT_NOT_FOUNDThe rule segment doesn’t exist or belongs to another application.
INVALID_SEGMENT_TYPEThe rule segment has a condition flags can’t evaluate: event, static, external, last update, or best time to send.
CONFIRM_REQUIREDReshuffle was sent without confirm: true.
TAG_CONFLICTThe account has a custom tag named PW_FF_ followed by the flag key.
FEATURE_FLAGS_NOT_ALLOWEDThe account’s plan doesn’t include feature flags.
FLAGS_LIMITThe application has as many non-archived flags as the plan allows.
VERSION_CONFLICTThe flag changed since the version you sent.
PAYLOAD_TOO_LARGEThe flags of the application would take more than 64 KB in one device’s answer.
STATUS_CONFLICTThe status doesn’t allow the operation, for example killing an archived flag.