curl --request POST \
--url https://api.visiqlabs.com/rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"operations": [
"action"
],
"name": "Block large refunds",
"rego_source": "package visiq\n\ndefault decision = \"permit\"\n\ndecision = \"deny\" {\n input.action == \"refund.create\"\n input.context.amount > 5000\n}\n",
"target_app": "stripe",
"priority": 50
}
'import requests
url = "https://api.visiqlabs.com/rules"
payload = {
"operations": ["action"],
"name": "Block large refunds",
"rego_source": "package visiq
default decision = \"permit\"
decision = \"deny\" {
input.action == \"refund.create\"
input.context.amount > 5000
}
",
"target_app": "stripe",
"priority": 50
}
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({
operations: ['action'],
name: 'Block large refunds',
rego_source: 'package visiq\n\ndefault decision = "permit"\n\ndecision = "deny" {\n input.action == "refund.create"\n input.context.amount > 5000\n}\n',
target_app: 'stripe',
priority: 50
})
};
fetch('https://api.visiqlabs.com/rules', 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.visiqlabs.com/rules",
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([
'operations' => [
'action'
],
'name' => 'Block large refunds',
'rego_source' => 'package visiq
default decision = "permit"
decision = "deny" {
input.action == "refund.create"
input.context.amount > 5000
}
',
'target_app' => 'stripe',
'priority' => 50
]),
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.visiqlabs.com/rules"
payload := strings.NewReader("{\n \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\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.visiqlabs.com/rules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.visiqlabs.com/rules")
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 \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"rule_code": "<string>",
"name": "<string>",
"description": "<string>",
"rego_source": "<string>",
"natural_language": "<string>",
"priority": 123,
"enabled": true,
"applies_to": [
"action"
],
"target_app": "<string>",
"action_pattern": "<string>",
"trust_tier": "<string>",
"surface": "<string>",
"principal_exclusions": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": "Invalid request body",
"code": "invalid_request",
"details": [
{
"path": [
"agent_id"
],
"message": "Required"
}
]
}{
"error": "Unauthorized",
"code": "unauthenticated"
}{
"error": "insufficient_scope",
"code": "insufficient_scope",
"detail": "This API key is not authorized for the requested operation."
}{
"error": "<string>",
"code": "<string>",
"detail": "<string>",
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"detail": "<string>",
"details": [
{}
]
}{
"error": "rate_limiter_unavailable",
"code": "rate_limiter_unavailable",
"detail": "Rate limiter unavailable, please retry."
}Create a rule
Create a rule tagged with the operations it governs. operations[] is mapped to applies_to. Requires permission allow_rules:create.
curl --request POST \
--url https://api.visiqlabs.com/rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"operations": [
"action"
],
"name": "Block large refunds",
"rego_source": "package visiq\n\ndefault decision = \"permit\"\n\ndecision = \"deny\" {\n input.action == \"refund.create\"\n input.context.amount > 5000\n}\n",
"target_app": "stripe",
"priority": 50
}
'import requests
url = "https://api.visiqlabs.com/rules"
payload = {
"operations": ["action"],
"name": "Block large refunds",
"rego_source": "package visiq
default decision = \"permit\"
decision = \"deny\" {
input.action == \"refund.create\"
input.context.amount > 5000
}
",
"target_app": "stripe",
"priority": 50
}
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({
operations: ['action'],
name: 'Block large refunds',
rego_source: 'package visiq\n\ndefault decision = "permit"\n\ndecision = "deny" {\n input.action == "refund.create"\n input.context.amount > 5000\n}\n',
target_app: 'stripe',
priority: 50
})
};
fetch('https://api.visiqlabs.com/rules', 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.visiqlabs.com/rules",
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([
'operations' => [
'action'
],
'name' => 'Block large refunds',
'rego_source' => 'package visiq
default decision = "permit"
decision = "deny" {
input.action == "refund.create"
input.context.amount > 5000
}
',
'target_app' => 'stripe',
'priority' => 50
]),
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.visiqlabs.com/rules"
payload := strings.NewReader("{\n \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\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.visiqlabs.com/rules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.visiqlabs.com/rules")
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 \"operations\": [\n \"action\"\n ],\n \"name\": \"Block large refunds\",\n \"rego_source\": \"package visiq\\n\\ndefault decision = \\\"permit\\\"\\n\\ndecision = \\\"deny\\\" {\\n input.action == \\\"refund.create\\\"\\n input.context.amount > 5000\\n}\\n\",\n \"target_app\": \"stripe\",\n \"priority\": 50\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"rule_code": "<string>",
"name": "<string>",
"description": "<string>",
"rego_source": "<string>",
"natural_language": "<string>",
"priority": 123,
"enabled": true,
"applies_to": [
"action"
],
"target_app": "<string>",
"action_pattern": "<string>",
"trust_tier": "<string>",
"surface": "<string>",
"principal_exclusions": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": "Invalid request body",
"code": "invalid_request",
"details": [
{
"path": [
"agent_id"
],
"message": "Required"
}
]
}{
"error": "Unauthorized",
"code": "unauthenticated"
}{
"error": "insufficient_scope",
"code": "insufficient_scope",
"detail": "This API key is not authorized for the requested operation."
}{
"error": "<string>",
"code": "<string>",
"detail": "<string>",
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"detail": "<string>",
"details": [
{}
]
}{
"error": "rate_limiter_unavailable",
"code": "rate_limiter_unavailable",
"detail": "Rate limiter unavailable, please retry."
}Authorizations
A VisIQ API key presented as Authorization: Bearer vq_prod_.... Mint harness keys under Settings → Harness Keys and API keys under Settings → API Keys in the dashboard.
Headers
Optional. Makes this write safe to retry: a repeat with the same key, method, path (including its query string) and body within 24 hours returns the stored response with X-Idempotent-Replayed: true instead of running again. Reusing the key with a different request is a 422; a repeat while the first is still running is a 409, until the first request's 2-minute processing lease expires, after which the repeat runs. See REST conventions.
1 - 256^[A-Za-z0-9_-]+$The legacy spelling of Idempotency-Key, accepted with the same behaviour. Sending both with different values is a 400.
1 - 256^[A-Za-z0-9_-]+$Body
The operations the rule governs, stored as applies_to. The list must include action or retrieval; delegation is only an additional tag, and a delegation-only list is refused with 400.
1 - 3 elementsaction, retrieval, delegation 1 - 2551 - 10000010002000255255641281 - 255Response
The created rule.
action, retrieval, delegation