curl --request POST \
--url https://api.osohq.com/api/evaluate_query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"predicate": [
"<unknown>"
],
"calls": [
[
"<unknown>"
]
],
"constraints": {},
"context_facts": [
{
"predicate": "<string>",
"args": [
{
"type": "<string>",
"id": "<string>"
}
]
}
]
}
'import os
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Basic query building
actor = Value("User", "alice")
repository = Value("Repository", "anvils")
query = oso.build_query(("allow", actor, "read", repository))
result = query.evaluate(repository)
# Add constraints with 'and_'
constrained_query = oso.build_query(("allow", actor, "read", repository)) \
.and_(("has_relation", repository, "folder", Value("Folder", "docs")))
# Different evaluation modes
exists = query.evaluate() # Boolean
actions = query.evaluate("action") # Single variable
pairs = query.evaluate(("action", "repository")) # Tuple variablesimport { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Basic query building
const actor = { type: "User", id: "alice" };
const repository = { type: "Repository", id: "anvils" };
const query = oso.buildQuery(["allow", actor, "read", repository]);
const result = await query.evaluate(repository);
// Add constraints with 'and'
const constrainedQuery = oso.buildQuery(["allow", actor, "read", repository])
.and(["has_relation", repository, "folder", { type: "Folder", id: "docs" }]);
// Different evaluation modes
const exists = await query.evaluate(); // Boolean
const actions = await query.evaluate("action"); // Single variable
const pairs = await query.evaluate(["action", "repository"]); // Tuple variablespackage main
import (
"log"
"os"
oso "github.com/osohq/go-oso-cloud/v2"
)
func main() {
apiKey := os.Getenv("OSO_CLOUD_API_KEY")
osoClient := oso.NewClient("https://cloud.osohq.com", apiKey)
// Basic query building
actor := oso.NewValue("User", "alice")
repository := oso.NewValue("Repository", "anvils")
query := osoClient.BuildQuery(oso.NewQueryFact("allow", actor, oso.String("read"), repository))
repos, err := query.EvaluateValues(repository)
// Add constraints with 'And'
folder := oso.NewValue("Folder", "docs")
constrainedQuery := osoClient.BuildQuery(oso.NewQueryFact("allow", actor, oso.String("read"), repository)).
And(oso.NewQueryFact("has_relation", repository, oso.String("folder"), folder))
// Different evaluation modes
allowed, err := query.EvaluateExists() // Boolean
actions, err := query.EvaluateValues(oso.NewVariable("action")) // Values for variable
}package com.mycompany;
import java.io.IOException;
import com.osohq.oso_cloud.Oso;
import com.osohq.oso_cloud.api.ApiException;
import com.osohq.oso_cloud.api.Value;
public class App {
public static void main(String[] args) {
String apiKey = System.getenv("OSO_CLOUD_API_KEY");
Oso oso = new Oso(apiKey);
try {
// Basic query building
Value actor = new Value("User", "alice");
Value repository = new Value("Repository", "anvils");
var query = oso.buildQuery("allow", actor, "read", repository);
var result = query.evaluate(repository);
// Add constraints with 'and'
Value folder = new Value("Folder", "docs");
var constrainedQuery = oso.buildQuery("allow", actor, "read", repository)
.and("has_relation", repository, "folder", folder);
// Different evaluation modes
boolean exists = query.evaluate(); // Boolean
var actions = query.evaluate("action"); // Single variable
var pairs = query.evaluate("action", "repository"); // Tuple variables
} catch (IOException | ApiException e) {
System.err.println("Error: " + e.getMessage());
}
}
}require 'oso-cloud'
api_key = ENV.fetch('OSO_CLOUD_API_KEY', nil)
oso = OsoCloud::Oso.new(url: "https://cloud.osohq.com", api_key: api_key)
# Basic query building
actor = OsoCloud::Value.new(type: "User", id: "alice")
repository = OsoCloud::Value.new(type: "Repository", id: "anvils")
query = oso.build_query(["allow", actor, "read", repository])
result = query.evaluate(repository)
# Add constraints with 'and_'
folder = OsoCloud::Value.new(type: "Folder", id: "docs")
constrained_query = oso.build_query(["allow", actor, "read", repository])
.and_(["has_relation", repository, "folder", folder])
# Different evaluation modes
exists = query.evaluate() # Boolean
actions = query.evaluate("action") # Single variable
pairs = query.evaluate(["action", "repository"]) # Tuple variablesusing OsoCloud;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Basic query building
var actor = new Value("User", "alice");
var repository = new Value("Repository", "anvils");
var query = oso.BuildQuery("allow", actor, "read", repository);
var result = await query.Evaluate(repository);
// Add constraints with 'And'
var folder = new Value("Folder", "docs");
var constrainedQuery = oso.BuildQuery("allow", actor, "read", repository)
.And("has_relation", repository, "folder", folder);
// Different evaluation modes
bool exists = await query.Evaluate(); // Boolean
var actions = await query.Evaluate("action"); // Single variable
var pairs = await query.Evaluate(new[] { "action", "repository" }); // Tuple variables{
"results": [
{}
]
}{
"message": "<string>"
}Post evaluate query
Query v2: query for any expression.
Unlike GET /facts, which only lists facts you’ve added to Oso Cloud, you can use POST /evaluate_query to list derived information about any rule in your policy.
curl --request POST \
--url https://api.osohq.com/api/evaluate_query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"predicate": [
"<unknown>"
],
"calls": [
[
"<unknown>"
]
],
"constraints": {},
"context_facts": [
{
"predicate": "<string>",
"args": [
{
"type": "<string>",
"id": "<string>"
}
]
}
]
}
'import os
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Basic query building
actor = Value("User", "alice")
repository = Value("Repository", "anvils")
query = oso.build_query(("allow", actor, "read", repository))
result = query.evaluate(repository)
# Add constraints with 'and_'
constrained_query = oso.build_query(("allow", actor, "read", repository)) \
.and_(("has_relation", repository, "folder", Value("Folder", "docs")))
# Different evaluation modes
exists = query.evaluate() # Boolean
actions = query.evaluate("action") # Single variable
pairs = query.evaluate(("action", "repository")) # Tuple variablesimport { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Basic query building
const actor = { type: "User", id: "alice" };
const repository = { type: "Repository", id: "anvils" };
const query = oso.buildQuery(["allow", actor, "read", repository]);
const result = await query.evaluate(repository);
// Add constraints with 'and'
const constrainedQuery = oso.buildQuery(["allow", actor, "read", repository])
.and(["has_relation", repository, "folder", { type: "Folder", id: "docs" }]);
// Different evaluation modes
const exists = await query.evaluate(); // Boolean
const actions = await query.evaluate("action"); // Single variable
const pairs = await query.evaluate(["action", "repository"]); // Tuple variablespackage main
import (
"log"
"os"
oso "github.com/osohq/go-oso-cloud/v2"
)
func main() {
apiKey := os.Getenv("OSO_CLOUD_API_KEY")
osoClient := oso.NewClient("https://cloud.osohq.com", apiKey)
// Basic query building
actor := oso.NewValue("User", "alice")
repository := oso.NewValue("Repository", "anvils")
query := osoClient.BuildQuery(oso.NewQueryFact("allow", actor, oso.String("read"), repository))
repos, err := query.EvaluateValues(repository)
// Add constraints with 'And'
folder := oso.NewValue("Folder", "docs")
constrainedQuery := osoClient.BuildQuery(oso.NewQueryFact("allow", actor, oso.String("read"), repository)).
And(oso.NewQueryFact("has_relation", repository, oso.String("folder"), folder))
// Different evaluation modes
allowed, err := query.EvaluateExists() // Boolean
actions, err := query.EvaluateValues(oso.NewVariable("action")) // Values for variable
}package com.mycompany;
import java.io.IOException;
import com.osohq.oso_cloud.Oso;
import com.osohq.oso_cloud.api.ApiException;
import com.osohq.oso_cloud.api.Value;
public class App {
public static void main(String[] args) {
String apiKey = System.getenv("OSO_CLOUD_API_KEY");
Oso oso = new Oso(apiKey);
try {
// Basic query building
Value actor = new Value("User", "alice");
Value repository = new Value("Repository", "anvils");
var query = oso.buildQuery("allow", actor, "read", repository);
var result = query.evaluate(repository);
// Add constraints with 'and'
Value folder = new Value("Folder", "docs");
var constrainedQuery = oso.buildQuery("allow", actor, "read", repository)
.and("has_relation", repository, "folder", folder);
// Different evaluation modes
boolean exists = query.evaluate(); // Boolean
var actions = query.evaluate("action"); // Single variable
var pairs = query.evaluate("action", "repository"); // Tuple variables
} catch (IOException | ApiException e) {
System.err.println("Error: " + e.getMessage());
}
}
}require 'oso-cloud'
api_key = ENV.fetch('OSO_CLOUD_API_KEY', nil)
oso = OsoCloud::Oso.new(url: "https://cloud.osohq.com", api_key: api_key)
# Basic query building
actor = OsoCloud::Value.new(type: "User", id: "alice")
repository = OsoCloud::Value.new(type: "Repository", id: "anvils")
query = oso.build_query(["allow", actor, "read", repository])
result = query.evaluate(repository)
# Add constraints with 'and_'
folder = OsoCloud::Value.new(type: "Folder", id: "docs")
constrained_query = oso.build_query(["allow", actor, "read", repository])
.and_(["has_relation", repository, "folder", folder])
# Different evaluation modes
exists = query.evaluate() # Boolean
actions = query.evaluate("action") # Single variable
pairs = query.evaluate(["action", "repository"]) # Tuple variablesusing OsoCloud;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Basic query building
var actor = new Value("User", "alice");
var repository = new Value("Repository", "anvils");
var query = oso.BuildQuery("allow", actor, "read", repository);
var result = await query.Evaluate(repository);
// Add constraints with 'And'
var folder = new Value("Folder", "docs");
var constrainedQuery = oso.BuildQuery("allow", actor, "read", repository)
.And("has_relation", repository, "folder", folder);
// Different evaluation modes
bool exists = await query.Evaluate(); // Boolean
var actions = await query.Evaluate("action"); // Single variable
var pairs = await query.Evaluate(new[] { "action", "repository" }); // Tuple variables{
"results": [
{}
]
}{
"message": "<string>"
}Authorizations
Requires an API key to access.
Body
A generic query comprising 1+ predicates conjuncted together.
Predicate name and variable names.
INVARIANT: all variable names must exist in constraints. This ensures that all variables at least have a type.
2 elementsPredicate name and variable names.
INVARIANT: all variable names must exist in constraints. This ensures that all variables at least have a type.
2 elementsMap of variable names to their type and value(s). Every variable is at least typed and may also be constrained to a set of values.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Response
Show child attributes
Show child attributes
Was this page helpful?