<!-- llms.txt: https://workos.com/llms.txt -->

# Targeting

Targeting allows you to enable Feature Flags for specific users or organizations. When a flag is enabled for a target, that target will receive the flag's enabled value instead of the default value.

## Add a feature flag target

Enables a feature flag for a specific target in the current environment. Currently, supported targets include users and organizations.

:::code-group{title="Request"}

```bash language="curl"
curl --request POST \
  --url https://api.workos.com/feature-flags/test-flag/targets/org_01EHZNVPK3SFK441A1RGBFSHRT \
  --header "Authorization: Bearer sk_example_123456789"
```

```js language="js"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

await workos.featureFlags.addFlagTarget({
  slug: 'test-flag',
  targetId: 'org_01EHZNVPK3SFK441A1RGBFSHRT',
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.feature_flags.add_flag_target(
  resource_id: "user_01234567890abcdef",
  slug: "beta-feature"
)
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.feature_flags.add_flag_target(
    resource_id="user_01234567890abcdef", slug="beta-feature"
)
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.FeatureFlags().AddFlagTarget(context.Background(), "user_01234567890abcdef", "beta-feature")
	if err != nil {
		panic(err)
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->featureFlags()
    ->addFlagTarget(resourceId: "user_01234567890abcdef", slug: "beta-feature");
```

```java language="java"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.featureFlags.addFlagTarget("user_01234567890abcdef", "beta-feature");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.FeatureFlags.AddFlagTargetAsync("user_01234567890abcdef", "beta-feature");
```

```rust language="rust"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .feature_flags()
        .add_flag_target(
            "user_01234567890abcdef",
            "beta-feature"
        )
        .await?;

    Ok(())
}
```

:::

## List enabled feature flags for an organization

Get a list of all enabled feature flags for an organization.

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/organizations/org_01EHZNVPK3SFK441A1RGBFSHRT/feature-flags" \
  --header "Authorization: Bearer sk_example_123456789"
```

```js language="js" title="Request" tab="1"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const featureFlags = await workos.organizations.listOrganizationFeatureFlags({
  organizationId: 'org_01EHZNVPK3SFK441A1RGBFSHRT',
});

console.log(featureFlags.data);
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.feature_flags.list_organization_feature_flags(organization_id: "org_01EHZNVPK3SFK441A1RGBFSHRT")
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.feature_flags.list_organization_feature_flags(
    organization_id="org_01EHZNVPK3SFK441A1RGBFSHRT"
)
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.FeatureFlags().ListOrganizationFeatureFlags(context.Background(), "org_01EHZNVPK3SFK441A1RGBFSHRT")
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->featureFlags()
    ->listOrganizationFeatureFlags(
        organizationId: "org_01EHZNVPK3SFK441A1RGBFSHRT",
    );
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.featureFlags.listOrganizationFeatureFlags("org_01EHZNVPK3SFK441A1RGBFSHRT");
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.FeatureFlags.ListOrganizationFeatureFlagsAsync("org_01EHZNVPK3SFK441A1RGBFSHRT");
```

```rust language="rust" title="Request" tab="1"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .feature_flags()
        .list_organization_feature_flags("org_01EHZNVPK3SFK441A1RGBFSHRT")
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "object": "list",
  "data": [
    {
      "object": "feature_flag",
      "id": "flag_01EHZNVPK3SFK441A1RGBFSHRT",
      "slug": "advanced-analytics",
      "name": "Advanced Analytics",
      "description": "Enable advanced analytics dashboard feature",
      "owner": {
        "email": "jane@example.com",
        "first_name": "Jane",
        "last_name": "Doe"
      },
      "tags": [
        "reports"
      ],
      "enabled": true,
      "default_value": false,
      "created_at": "2026-01-15T12:00:00.000Z",
      "updated_at": "2026-01-15T12:00:00.000Z"
    }
  ],
  "list_metadata": {
    "before": "flag_01HXYZ123456789ABCDEFGHIJ",
    "after": "flag_01HXYZ987654321KJIHGFEDCBA"
  }
}
```

:::

## List enabled feature flags for a user

Get a list of all enabled feature flags for the provided user. This includes feature flags enabled specifically for the user as well as any organizations that the user is a member of.

:::code-group

```bash language="curl" title="Request" tab="1"
curl "https://api.workos.com/user_management/users/user_01E4ZCR3C56J083X43JQXF3JK5/feature-flags" \
  --header "Authorization: Bearer sk_example_123456789"
```

```js language="js" title="Request" tab="1"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

const featureFlags = await workos.userManagement.listUserFeatureFlags({
  userId: 'user_01EHZNVPK3SFK441A1RGBFSHRT',
});

console.log(featureFlags.data);
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.feature_flags.list_user_feature_flags(user_id: "user_01E4ZCR3C56J083X43JQXF3JK5")
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.feature_flags.list_user_feature_flags(user_id="user_01E4ZCR3C56J083X43JQXF3JK5")
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.FeatureFlags().ListUserFeatureFlags(context.Background(), "user_01E4ZCR3C56J083X43JQXF3JK5")
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->featureFlags()
    ->listUserFeatureFlags(userId: "user_01E4ZCR3C56J083X43JQXF3JK5");
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.featureFlags.listUserFeatureFlags("user_01E4ZCR3C56J083X43JQXF3JK5");
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.FeatureFlags.ListUserFeatureFlagsAsync("user_01E4ZCR3C56J083X43JQXF3JK5");
```

```rust language="rust" title="Request" tab="1"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .feature_flags()
        .list_user_feature_flags("user_01E4ZCR3C56J083X43JQXF3JK5")
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "object": "list",
  "data": [
    {
      "object": "feature_flag",
      "id": "flag_01EHZNVPK3SFK441A1RGBFSHRT",
      "slug": "advanced-analytics",
      "name": "Advanced Analytics",
      "description": "Enable advanced analytics dashboard feature",
      "owner": {
        "email": "jane@example.com",
        "first_name": "Jane",
        "last_name": "Doe"
      },
      "tags": [
        "reports"
      ],
      "enabled": true,
      "default_value": false,
      "created_at": "2026-01-15T12:00:00.000Z",
      "updated_at": "2026-01-15T12:00:00.000Z"
    }
  ],
  "list_metadata": {
    "before": "flag_01HXYZ123456789ABCDEFGHIJ",
    "after": "flag_01HXYZ987654321KJIHGFEDCBA"
  }
}
```

:::

## Remove a feature flag target

Removes a target from the feature flag's target list in the current environment. Currently, supported targets include users and organizations.

:::code-group{title="Request"}

```bash language="curl"
curl --request DELETE \
  --url https://api.workos.com/feature-flags/test-flag/targets/org_01EHZNVPK3SFK441A1RGBFSHRT \
  --header "Authorization: Bearer sk_example_123456789"
```

```js language="js"
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

await workos.featureFlags.removeFlagTarget({
  slug: 'test-flag',
  targetId: 'org_01EHZNVPK3SFK441A1RGBFSHRT',
});
```

```rb language="ruby"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.feature_flags.remove_flag_target(
  resource_id: "user_01234567890abcdef",
  slug: "beta-feature"
)
```

```py language="python"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.feature_flags.remove_flag_target(
    resource_id="user_01234567890abcdef", slug="beta-feature"
)
```

```go language="go"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.FeatureFlags().RemoveFlagTarget(context.Background(), "user_01234567890abcdef", "beta-feature")
	if err != nil {
		panic(err)
	}
}
```

```php language="php"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->featureFlags()
    ->removeFlagTarget(
        resourceId: "user_01234567890abcdef",
        slug: "beta-feature",
    );
```

```java language="java"
import com.workos.WorkOS;

WorkOS workos = new WorkOS("sk_example_123456789");

workos.featureFlags.removeFlagTarget("user_01234567890abcdef", "beta-feature");
```

```cs language="dotnet"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.FeatureFlags.RemoveFlagTargetAsync("user_01234567890abcdef", "beta-feature");
```

```rust language="rust"
use workos::Client;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .feature_flags()
        .remove_flag_target(
            "user_01234567890abcdef",
            "beta-feature"
        )
        .await?;

    Ok(())
}
```

:::

### flag_target

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `target_id` | string | Yes | The ID of the target (user or organization) that a Feature Flag is enabled for. |

### POST /feature-flags/{slug}/targets/{resourceId}

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | string | Yes | The resource ID in format "user_&lt;id&gt;" or "org_&lt;id&gt;". |
| `slug` | string | Yes | The unique slug identifier of the feature flag. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `empty` | empty | Returns an empty response on success. |

### GET /organizations/{organizationId}/feature-flags

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `organizationId` | string | Yes | Unique identifier of the Organization. |
| `before` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `after` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `limit` | integer | No | Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`. |
| `order` | "normal" \| "desc" \| "asc" | No | Order the results by the creation time. Defaults to `desc`. |

### GET /user_management/users/{userId}/feature-flags

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `userId` | string | Yes | The ID of the user. |
| `before` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `after` | string | No | An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. |
| `limit` | integer | No | Upper limit on the number of objects to return, between `1` and `100`. Defaults to `10`. |
| `order` | "normal" \| "desc" \| "asc" | No | Order the results by the creation time. Defaults to `desc`. |

### DELETE /feature-flags/{slug}/targets/{resourceId}

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | string | Yes | The resource ID in format "user_&lt;id&gt;" or "org_&lt;id&gt;". |
| `slug` | string | Yes | The unique slug identifier of the feature flag. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `empty` | empty | Returns an empty response on success. |