Update AI Config targeting

Perform a partial update to an AI Config’s targeting. The request body must be a valid semantic patch.

Using semantic patches on an AI Config

To make a semantic patch request, you must append domain-model=launchdarkly.semanticpatch to your Content-Type header. To learn more, read Updates using semantic patch.

The body of a semantic patch request for updating an AI Config’s targeting takes the following properties:

  • comment (string): (Optional) A description of the update.
  • environmentKey (string): The key of the LaunchDarkly environment.
  • instructions (array): (Required) A list of actions the update should perform. Each action in the list must be an object with a kind property that indicates the instruction. If the action requires parameters, you must include those parameters as additional fields in the object. The body of a single semantic patch can contain many different instructions.

Instructions

Semantic patch requests support the following kind instructions for updating AI Configs.

Click to expand instructions for working with targeting and variations for AI Configs

addClauses

Adds the given clauses to the rule indicated by ruleId.

Parameters
  • ruleId: ID of a rule in the AI Config.
  • clauses: Array of clause objects, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.

Here’s an example:

1{
2 "environmentKey": "environment-key-123abc",
3 "instructions": [{
4 "kind": "addClauses",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauses": [{
7 "contextKind": "user",
8 "attribute": "country",
9 "op": "in",
10 "negate": false,
11 "values": ["USA", "Canada"]
12 }]
13 }]
14}

addRule

Adds a new targeting rule to the AI Config. The rule may contain clauses and serve the variation that variationId indicates, or serve a percentage rollout that rolloutWeights, rolloutBucketBy, and rolloutContextKind indicate.

If you set beforeRuleId, this adds the new rule before the indicated rule. Otherwise, adds the new rule to the end of the list.

Parameters
  • clauses: Array of clause objects, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.
  • beforeRuleId: (Optional) ID of a rule.
  • Either
  • variationId: ID of a variation.

or

  • rolloutWeights: (Optional) Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example that uses a variationId:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addRule",
5 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
6 "clauses": [{
7 "contextKind": "organization",
8 "attribute": "located_in",
9 "op": "in",
10 "negate": false,
11 "values": ["Sweden", "Norway"]
12 }]
13}]
14}

Here’s an example that uses a percentage rollout:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addRule",
5 "clauses": [{
6 "contextKind": "organization",
7 "attribute": "located_in",
8 "op": "in",
9 "negate": false,
10 "values": ["Sweden", "Norway"]
11 }],
12 "rolloutContextKind": "organization",
13 "rolloutWeights": {
14 "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation
15 "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation
16 }
17}]
18}

addTargets

Adds context keys to the individual context targets for the context kind that contextKind specifies and the variation that variationId specifies. Returns an error if this causes the AI Config to target the same context key in multiple variations.

Parameters
  • values: List of context keys.
  • contextKind: (Optional) Context kind to target, defaults to user
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addTargets",
5 "values": ["context-key-123abc", "context-key-456def"],
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

addValuesToClause

Adds values to the values of the clause that ruleId and clauseId indicate. Does not update the context kind, attribute, or operator.

Parameters
  • ruleId: ID of a rule in the AI Config.
  • clauseId: ID of a clause in that rule.
  • values: Array of strings, case sensitive.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "addValuesToClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
7 "values": ["beta_testers"]
8}]
9}

clearTargets

Removes all individual targets from the variation that variationId specifies. This includes both user and non-user targets.

Parameters
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "clearTargets", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ]
4}

removeClauses

Removes the clauses specified by clauseIds from the rule indicated by ruleId.

Parameters
  • ruleId: ID of a rule.
  • clauseIds: Array of IDs of clauses in the rule.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeClauses",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseIds": ["10a58772-3121-400f-846b-b8a04e8944ed", "36a461dc-235e-4b08-97b9-73ce9365873e"]
7}]
8}

removeRule

Removes the targeting rule specified by ruleId. Does nothing if the rule does not exist.

Parameters
  • ruleId: ID of a rule.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "removeRule", "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29" } ]
4}

removeTargets

Removes context keys from the individual context targets for the context kind that contextKind specifies and the variation that variationId specifies. Does nothing if the flag does not target the context keys.

Parameters
  • values: List of context keys.
  • contextKind: (Optional) Context kind to target, defaults to user
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeTargets",
5 "values": ["context-key-123abc", "context-key-456def"],
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

removeValuesFromClause

Removes values from the values of the clause indicated by ruleId and clauseId. Does not update the context kind, attribute, or operator.

Parameters
  • ruleId: ID of a rule.
  • clauseId: ID of a clause in that rule.
  • values: Array of strings, case sensitive.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "removeValuesFromClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
7 "values": ["beta_testers"]
8}]
9}

reorderRules

Rearranges the rules to match the order given in ruleIds. Returns an error if ruleIds does not match the current set of rules on the AI Config.

Parameters
  • ruleIds: Array of IDs of all rules.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "reorderRules",
5 "ruleIds": ["a902ef4a-2faf-4eaf-88e1-ecc356708a29", "63c238d1-835d-435e-8f21-c8d5e40b2a3d"]
6}]
7}

replaceRules

Removes all targeting rules for the AI Config and replaces them with the list you provide.

Parameters
  • rules: A list of rules.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [
4 {
5 "kind": "replaceRules",
6 "rules": [
7 {
8 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
9 "description": "My new rule",
10 "clauses": [
11 {
12 "contextKind": "user",
13 "attribute": "segmentMatch",
14 "op": "segmentMatch",
15 "values": ["test"]
16 }
17 ]
18 }
19 ]
20 }
21]
22}

replaceTargets

Removes all existing targeting and replaces it with the list of targets you provide.

Parameters
  • targets: A list of context targeting. Each item in the list includes an optional contextKind that defaults to user, a required variationId, and a required list of values.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [
4 {
5 "kind": "replaceTargets",
6 "targets": [
7 {
8 "contextKind": "user",
9 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00",
10 "values": ["user-key-123abc"]
11 },
12 {
13 "contextKind": "device",
14 "variationId": "e5830889-1ec5-4b0c-9cc9-c48790090c43",
15 "values": ["device-key-456def"]
16 }
17 ]
18 }
19]
20}

updateClause

Replaces the clause indicated by ruleId and clauseId with clause.

Parameters
  • ruleId: ID of a rule.
  • clauseId: ID of a clause in that rule.
  • clause: New clause object, with contextKind (string), attribute (string), op (string), negate (boolean), and values (array of strings, numbers, or dates) properties. The contextKind, attribute, and values are case sensitive. The op must be lower-case.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateClause",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "clauseId": "10c7462a-2062-45ba-a8bb-dfb3de0f8af5",
7 "clause": {
8 "contextKind": "user",
9 "attribute": "country",
10 "op": "in",
11 "negate": false,
12 "values": ["Mexico", "Canada"]
13 }
14}]
15}

updateDefaultVariation

Updates the default on or off variation of the AI Config.

Parameters
  • onVariationValue: (Optional) The value of the variation of the new on variation.
  • offVariationValue: (Optional) The value of the variation of the new off variation

Here’s an example:

1{
2"instructions": [ { "kind": "updateDefaultVariation", "OnVariationValue": true, "OffVariationValue": false } ]
3}

updateFallthroughVariationOrRollout

Updates the default or “fallthrough” rule for the AI Config, which the AI Config serves when a context matches none of the targeting rules. The rule can serve either the variation that variationId indicates, or a percentage rollout that rolloutWeights and rolloutBucketBy indicate.

Parameters
  • variationId: ID of a variation.

or

  • rolloutWeights: Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example that uses a variationId:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateFallthroughVariationOrRollout",
5 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
6}]
7}

Here’s an example that uses a percentage rollout:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateFallthroughVariationOrRollout",
5 "rolloutContextKind": "user",
6 "rolloutWeights": {
7 "2f43f67c-3e4e-4945-a18a-26559378ca00": 15000, // serve 15% this variation
8 "e5830889-1ec5-4b0c-9cc9-c48790090c43": 85000 // serve 85% this variation
9 }
10}]
11}

updateOffVariation

Updates the default off variation to variationId. The AI Config serves the default off variation when the AI Config’s targeting is Off.

Parameters
  • variationId: ID of a variation.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateOffVariation", "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00" } ]
4}

updateRuleDescription

Updates the description of the targeting rule.

Parameters
  • description: The new human-readable description for this rule.
  • ruleId: The ID of the rule. You can retrieve this by making a GET request for the AI Config.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleDescription",
5 "description": "New rule description",
6 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29"
7}]
8}

updateRuleTrackEvents

Updates whether or not LaunchDarkly tracks events for the AI Config associated with this rule.

Parameters
  • ruleId: The ID of the rule. You can retrieve this by making a GET request for the AI Config.
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleTrackEvents",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "trackEvents": true
7}]
8}

updateRuleVariationOrRollout

Updates what ruleId serves when its clauses evaluate to true. The rule can serve either the variation that variationId indicates, or a percent rollout that rolloutWeights and rolloutBucketBy indicate.

Parameters
  • ruleId: ID of a rule.
  • variationId: ID of a variation.

or

  • rolloutWeights: Map of variationId to weight, in thousandths of a percent (0-100000).
  • rolloutBucketBy: (Optional) Context attribute available in the specified rolloutContextKind.
  • rolloutContextKind: (Optional) Context kind, defaults to user

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [{
4 "kind": "updateRuleVariationOrRollout",
5 "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
6 "variationId": "2f43f67c-3e4e-4945-a18a-26559378ca00"
7}]
8}

updateTrackEvents

Updates whether or not LaunchDarkly tracks events for the AI Config, for all rules.

Parameters
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateTrackEvents", "trackEvents": true } ]
4}

updateTrackEventsFallthrough

Updates whether or not LaunchDarkly tracks events for the AI Config, for the default rule.

Parameters
  • trackEvents: Whether or not events are tracked.

Here’s an example:

1{
2"environmentKey": "environment-key-123abc",
3"instructions": [ { "kind": "updateTrackEventsFallthrough", "trackEvents": true } ]
4}

Path parameters

projectKeystringRequired
configKeystringRequired

Headers

AuthorizationstringRequired
LD-API-Version"beta"Required
Version of the endpoint.

Request

This endpoint expects an object.
environmentKeystringRequired
instructionslist of maps from strings to anyRequired
commentstringOptional

Response

AI Config targeting updated
createdAtlong
Unix timestamp in milliseconds
environmentsmap from strings to objects
experimentsobject
keystring
namestring
tagslist of strings
variationslist of objects
_versioninteger
defaultsobject or null

Errors