Link a feature to a Contextual Bandit
Adds a contextual-bandit-ref rule to the bottom of the feature’s rule list and links the feature to this contextual bandit. The rule 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.
POST
/
v1
/
contextual-bandits
/
{id}
/
linked-feature
/
{featureId}
cURL
curl -X POST '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.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
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 => "POST",
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("POST", 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.post("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::Post.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>",
"ruleId": "<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
bearerAuthbasicAuth
Body
application/json
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?
⌘I
cURL
curl -X POST '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.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
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 => "POST",
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("POST", 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.post("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::Post.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>",
"ruleId": "<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>"
]
}
}
