Skip to main content
Report when your application uses flags by applying them.
See Apply a Flag in the reference for details on why applies matter, when to apply, batching strategies, and best practices.

Before You Begin

Before applying flags, you must:
  1. Resolve flags to get variant values and a resolve token
  2. Save the resolveToken from the resolve response
  3. Use the flag value in your application

Apply a Single Flag

Report that a flag was applied:
curl -X POST "https://api.confidence.dev/v1/flags:apply" \
  -H "Content-Type: application/json" \
  -d '{
    "clientSecret": "YOUR_CLIENT_SECRET",
    "resolveToken": "<resolve token from resolve call>",
    "flags": [
      {
        "flag": "flags/image-size",
        "appliedTime": "2023-03-06T19:45:07.436Z",
        "sentTime": "2023-03-06T19:45:08.002Z"
      }
    ]
  }'

Apply Multiple Flags

Batch multiple applies together (recommended):
curl -X POST "https://api.confidence.dev/v1/flags:apply" \
  -H "Content-Type: application/json" \
  -d '{
    "clientSecret": "YOUR_CLIENT_SECRET",
    "resolveToken": "<resolve token>",
    "flags": [
      {
        "flag": "flags/image-size",
        "appliedTime": "2023-03-06T19:45:07.436Z",
        "sentTime": "2023-03-06T19:45:08.002Z"
      },
      {
        "flag": "flags/button-colors",
        "appliedTime": "2023-03-06T19:45:09.123Z",
        "sentTime": "2023-03-06T19:45:10.002Z"
      }
    ]
  }'

Complete Workflow

Here’s the full workflow from resolve to apply:
# Step 1: Resolve flags
RESPONSE=$(curl -X POST "https://api.confidence.dev/v1/flags:resolve" \
  -H "Content-Type: application/json" \
  -d '{
    "clientSecret": "YOUR_CLIENT_SECRET",
    "evaluationContext": {
      "user_id": "user123"
    }
  }')

# Step 2: Extract resolve token
RESOLVE_TOKEN=$(echo $RESPONSE | jq -r '.resolveToken')

# Step 3: Use flag values in your application
# (Your application code here)

# Step 4: Report that flags were applied
curl -X POST "https://api.confidence.dev/v1/flags:apply" \
  -H "Content-Type: application/json" \
  -d "{
    \"clientSecret\": \"YOUR_CLIENT_SECRET\",
    \"resolveToken\": \"$RESOLVE_TOKEN\",
    \"flags\": [
      {
        \"flag\": \"flags/my-flag\",
        \"appliedTime\": \"$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")\",
        \"sentTime\": \"$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")\"
      }
    ]
  }"

Next Steps

After applying flags:
  1. Monitor flag applied data in your data warehouse
  2. Use the data to analyze experiments
  3. Review apply patterns to optimize flag usage