0

I am trying to manage feature flag variations for groups of users via the LaunchDarkly API. My goal is to migrate users in groups, switching variations on a flag for specific segments, so I can change application behavior for certain users and gradually migrate them back and forth.

Here’s what I tried:

1. Create a segment

curl -X POST https://app.launchdarkly.com/api/v2/segments/someproject/someenv \
 -H "Authorization: api-XXXX" \
 -H "Content-Type: application/json; domain-model=launchdarkly.semanticpatch" \
 -d '{
       "name": "Group 1",
       "key": "group-1"
     }'

2. Add users to the segment

curl -X PATCH https://app.launchdarkly.com/api/v2/segments/someproject/someenv/group-1 \
 -H "Authorization: api-XXXX" \
 -H "Content-Type: application/json; domain-model=launchdarkly.semanticpatch" \
 -d '{
       "instructions": [{
         "kind": "addIncludedUsers",
         "values": [ "user-key-123abc", "user-key-456def" ]
       }]
     }'

3. Add the segment as a target to a flag variation

curl -X PATCH "https://app.launchdarkly.com/api/v2/flags/someproject/Migrations.someflag" \
 -H "Authorization: api-XXXX" \
 -H "Content-Type: application/json; domain-model=launchdarkly.semanticpatch" \
 -d '{
       "environmentKey": "someenv",
       "instructions": [{
         "kind": "addTargets",
         "variationId": "123123",
         "values": ["group-1"],
         "contextKind": "segment"
       }]
     }'

Problem:

I can create the segment and add users, but when I try to assign it to a flag variation, LaunchDarkly adds an individual user with key "italy-group-1" instead of applying the segment.

Goal:

I want to:

  • Define multiple user groups (segments)

  • Assign flag variations to segments, not individual users

  • Gradually migrate users to different variations and revert them if needed

How can I correctly add a segment to a feature flag variation via the API so that the flag recognizes all users in the segment?

1 Answer 1

0

This one worked.

curl -X PATCH "https://app.launchdarkly.com/api/v2/flags/some_project/Migrations.someflag" \
      -H "Authorization: api-xxxx" \
      -H "Content-Type: application/json; domain-model=launchdarkly.semanticpatch" \
      -d '{
    "environmentKey": "mock",
    "instructions": [
      {
        "kind": "addRule",
          "variationId":"someid",
          "clauses": [
            {
              "op": "segmentMatch",
              "values": ["italy-group-1"],
              "contextKind": "user"
            }
          ]
        
      }
    ]
  }'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.