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,
"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,
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,
'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 \"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 \"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 \"draftVersion\": 123\n}"
response = http.request(request)
puts response.read_body{
"featureId": "<string>",
"ruleIds": [
"<string>"
],
"revisionVersion": 123,
"published": true
}Authorizations
If using Bearer auth, pass the Secret Key as the token:
curl https://api.growthbook.io/api/v1/features -H "Authorization: Bearer secret_abc123DEF456"
Path Parameters
The Contextual Bandit id
The linked feature id
Body
One entry per Contextual Bandit variation. Every variation must be covered exactly once.
1Show child attributes
Show child attributes
Apply the rule in every environment. Defaults to true.
Environments to apply the rule in when not all.
Publish the resulting revision immediately instead of leaving it as a draft.
Update the rule on this existing draft revision instead of starting a new one.
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,
"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,
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,
'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 \"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 \"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 \"draftVersion\": 123\n}"
response = http.request(request)
puts response.read_body{
"featureId": "<string>",
"ruleIds": [
"<string>"
],
"revisionVersion": 123,
"published": true
}
