Replace a Contextual Bandit's rule on a linked feature
Replaces every contextual-bandit-ref rule pointing at this contextual bandit on the feature, keeping each rule’s id and position in the rule list. Every field is replaced, so omitted optional fields revert to their defaults. Returns a 400 when the feature has no such rule on the target revision, or when it has several that are not identical to each other. The change lands in a draft revision that auto-publishes when the contextual bandit starts, unless autoPublish is set. Targeting (condition, Saved Groups, prerequisites, coverage) is inherited from the contextual bandit and cannot be set on the rule.
curl -X PUT 'https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}' \
-H 'Authorization: Bearer YOUR_API_KEY'import requests
url = "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}"
payload = {
"variations": [
{
"variationId": "<string>",
"value": "<string>",
"config": "<string>"
}
],
"description": "<string>",
"enabled": True,
"allEnvironments": True,
"environments": ["<string>"],
"allProjects": True,
"projects": ["<string>"],
"autoPublish": True,
"allowUnscopedRules": True,
"draftVersion": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
variations: [{variationId: '<string>', value: '<string>', config: '<string>'}],
description: '<string>',
enabled: true,
allEnvironments: true,
environments: ['<string>'],
allProjects: true,
projects: ['<string>'],
autoPublish: true,
allowUnscopedRules: true,
draftVersion: 123
})
};
fetch('https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'variations' => [
[
'variationId' => '<string>',
'value' => '<string>',
'config' => '<string>'
]
],
'description' => '<string>',
'enabled' => true,
'allEnvironments' => true,
'environments' => [
'<string>'
],
'allProjects' => true,
'projects' => [
'<string>'
],
'autoPublish' => true,
'allowUnscopedRules' => true,
'draftVersion' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}"
payload := strings.NewReader("{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}"
response = http.request(request)
puts response.read_body{
"featureId": "<string>",
"ruleIds": [
"<string>"
],
"revisionVersion": 123,
"published": true
}{
"confirmation": {
"id": "<string>",
"status": "pending",
"actions": [
{
"action": "feature.create",
"environments": [
"<string>"
]
}
],
"summary": "<string>",
"url": "<string>",
"expiresAt": "<string>",
"response": {
"status": 123,
"body": "<unknown>"
},
"note": "<string>"
},
"message": "<string>"
}{
"message": "<string>",
"code": "unscoped_rule",
"details": {
"ruleIds": [
"<string>"
]
}
}Authorizations
Body
When the organization requires rules to target specific environments or Projects, set to true to save a rule that applies to All Environments and All Projects. Only set this when a person has explicitly asked you to. If a check blocks you, stop and ask a person instead of working around it.
Was this page helpful?
curl -X PUT 'https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}' \
-H 'Authorization: Bearer YOUR_API_KEY'import requests
url = "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}"
payload = {
"variations": [
{
"variationId": "<string>",
"value": "<string>",
"config": "<string>"
}
],
"description": "<string>",
"enabled": True,
"allEnvironments": True,
"environments": ["<string>"],
"allProjects": True,
"projects": ["<string>"],
"autoPublish": True,
"allowUnscopedRules": True,
"draftVersion": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
variations: [{variationId: '<string>', value: '<string>', config: '<string>'}],
description: '<string>',
enabled: true,
allEnvironments: true,
environments: ['<string>'],
allProjects: true,
projects: ['<string>'],
autoPublish: true,
allowUnscopedRules: true,
draftVersion: 123
})
};
fetch('https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'variations' => [
[
'variationId' => '<string>',
'value' => '<string>',
'config' => '<string>'
]
],
'description' => '<string>',
'enabled' => true,
'allEnvironments' => true,
'environments' => [
'<string>'
],
'allProjects' => true,
'projects' => [
'<string>'
],
'autoPublish' => true,
'allowUnscopedRules' => true,
'draftVersion' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}"
payload := strings.NewReader("{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.growthbook.io/api/v1/contextual-bandits/{id}/linked-feature/{featureId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"variations\": [\n {\n \"variationId\": \"<string>\",\n \"value\": \"<string>\",\n \"config\": \"<string>\"\n }\n ],\n \"description\": \"<string>\",\n \"enabled\": true,\n \"allEnvironments\": true,\n \"environments\": [\n \"<string>\"\n ],\n \"allProjects\": true,\n \"projects\": [\n \"<string>\"\n ],\n \"autoPublish\": true,\n \"allowUnscopedRules\": true,\n \"draftVersion\": 123\n}"
response = http.request(request)
puts response.read_body{
"featureId": "<string>",
"ruleIds": [
"<string>"
],
"revisionVersion": 123,
"published": true
}{
"confirmation": {
"id": "<string>",
"status": "pending",
"actions": [
{
"action": "feature.create",
"environments": [
"<string>"
]
}
],
"summary": "<string>",
"url": "<string>",
"expiresAt": "<string>",
"response": {
"status": 123,
"body": "<unknown>"
},
"note": "<string>"
},
"message": "<string>"
}{
"message": "<string>",
"code": "unscoped_rule",
"details": {
"ruleIds": [
"<string>"
]
}
}
