> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply Flags

> Learn how to track flag usage by applying flags.

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Apply Flags"
  description="Learn how to track flag usage by applying flags."
  steps={[
{
  name: "Before You Begin",
  text: "Before applying flags, you must: 1. Resolve flags to get variant values and a resolve token 2. Save the resolveToken from the resolve response",
},
{ name: "Apply a Single Flag", text: "Report that a flag was applied:" },
{
  name: "Apply Multiple Flags",
  text: "Batch multiple applies together (recommended):",
},
{
  name: "Complete Workflow",
  text: "Here's the full workflow from resolve to apply:",
},
]}
/>

Report when your application uses flags by applying them.

<Tip>
  See [Apply a Flag](../../flags/resolution-reference#apply-a-flag) in the reference for details on why applies matter, when to apply, batching strategies, and best practices.
</Tip>

## Before You Begin

Before applying flags, you must:

1. [Resolve flags](./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:

```bash theme={null}
curl -X POST "https://flags.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):

```bash theme={null}
curl -X POST "https://flags.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:

```bash theme={null}
# Step 1: Resolve flags
RESPONSE=$(curl -X POST "https://flags.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://flags.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
