Skip to main content
POST
/
orgs
/
{org_id}
/
k2
/
{kb_id}
/
policies
/
{policy_id}
/
assignments
cURL
curl --request POST \
  --url https://api.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "role_id": "<string>",
  "enabled": true,
  "priority": 123,
  "valid_from": "2023-11-07T05:31:56Z",
  "valid_until": "2023-11-07T05:31:56Z"
}
'
import requests

url = "https://api.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments"

payload = {
"role_id": "<string>",
"enabled": True,
"priority": 123,
"valid_from": "2023-11-07T05:31:56Z",
"valid_until": "2023-11-07T05:31:56Z"
}
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({
role_id: '<string>',
enabled: true,
priority: 123,
valid_from: '2023-11-07T05:31:56Z',
valid_until: '2023-11-07T05:31:56Z'
})
};

fetch('https://api.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments', 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.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments",
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([
'role_id' => '<string>',
'enabled' => true,
'priority' => 123,
'valid_from' => '2023-11-07T05:31:56Z',
'valid_until' => '2023-11-07T05:31:56Z'
]),
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.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments"

payload := strings.NewReader("{\n \"role_id\": \"<string>\",\n \"enabled\": true,\n \"priority\": 123,\n \"valid_from\": \"2023-11-07T05:31:56Z\",\n \"valid_until\": \"2023-11-07T05:31:56Z\"\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.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"role_id\": \"<string>\",\n \"enabled\": true,\n \"priority\": 123,\n \"valid_from\": \"2023-11-07T05:31:56Z\",\n \"valid_until\": \"2023-11-07T05:31:56Z\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.timbal.ai/orgs/{org_id}/k2/{kb_id}/policies/{policy_id}/assignments")

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 \"role_id\": \"<string>\",\n \"enabled\": true,\n \"priority\": 123,\n \"valid_from\": \"2023-11-07T05:31:56Z\",\n \"valid_until\": \"2023-11-07T05:31:56Z\"\n}"

response = http.request(request)
puts response.read_body
{
  "created_at": "2023-11-07T05:31:56Z",
  "enabled": true,
  "granted_at": "2023-11-07T05:31:56Z",
  "id": "<string>",
  "policy_id": "<string>",
  "priority": 123,
  "role_id": "<string>",
  "updated_at": "2023-11-07T05:31:56Z",
  "granted_by": "<string>",
  "revoked_at": "2023-11-07T05:31:56Z",
  "revoked_by": "<string>",
  "valid_from": "2023-11-07T05:31:56Z",
  "valid_until": "2023-11-07T05:31:56Z"
}
{
"code": "<string>",
"message": "<string>"
}
{
"code": "<string>",
"message": "<string>"
}

Authorizations

Authorization
string
header
required

Timbal API key. Obtain your API key from the Timbal platform settings. See Authentication for more information.

Path Parameters

org_id
string
required
kb_id
string
required
policy_id
string
required

Body

application/json
role_id
string
required
combine_mode
enum<string>

Postgres-RLS-style combination semantic for a policy binding.

Available options:
restrictive,
permissive
enabled
boolean
priority
integer<int32>
valid_from
string<date-time> | null
valid_until
string<date-time> | null

Response

Assignment created or re-attached

combine_mode
enum<string>
required

Postgres-RLS-style combination semantic for a policy binding.

Available options:
restrictive,
permissive
created_at
string<date-time>
required
enabled
boolean
required
granted_at
string<date-time>
required
id
string
required
policy_id
string
required
priority
integer<int32>
required
role_id
string
required
updated_at
string<date-time>
required
granted_by
string | null
revoked_at
string<date-time> | null
revoked_by
string | null
valid_from
string<date-time> | null
valid_until
string<date-time> | null