Simulate IAM decisions
Decides a list of requests for a user or a service account as if it held exactly the given roles instead of its current grants, whether or not the organization has enabled IAM. Nothing is changed, so this is how a role is tested before it is granted. One decision comes back per request, in the same order.
A simulate names 1 to 10 roles of the organization and 1 to 50 requests, each an exact action ID. A role of another organization, a wildcard, or an unknown action answers 422. Simulate decides from the given roles only, so it applies neither an API key’s scope nor the actions a signed-in user always keeps. The organization owner holds no roles, so the given roles do not change the owner’s decisions.
Only the organization owner can call this endpoint. Its action is iam.simulate. Other users and service account tokens get 403.
curl --request POST \
--url https://api.telnyx.com/v2/iam/simulate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"principal_type": "user",
"principal_id": "b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13",
"with_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"requests": [
{
"action": "number_order.create"
},
{
"action": "number.delete"
}
]
}
'import requests
url = "https://api.telnyx.com/v2/iam/simulate"
payload = {
"principal_type": "user",
"principal_id": "b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13",
"with_role_ids": ["8c4a9715-0246-4c6f-9eca-390e13bd8af0"],
"requests": [{ "action": "number_order.create" }, { "action": "number.delete" }]
}
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({
principal_type: 'user',
principal_id: 'b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13',
with_role_ids: ['8c4a9715-0246-4c6f-9eca-390e13bd8af0'],
requests: [{action: 'number_order.create'}, {action: 'number.delete'}]
})
};
fetch('https://api.telnyx.com/v2/iam/simulate', 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.telnyx.com/v2/iam/simulate",
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([
'principal_type' => 'user',
'principal_id' => 'b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13',
'with_role_ids' => [
'8c4a9715-0246-4c6f-9eca-390e13bd8af0'
],
'requests' => [
[
'action' => 'number_order.create'
],
[
'action' => 'number.delete'
]
]
]),
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.telnyx.com/v2/iam/simulate"
payload := strings.NewReader("{\n \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\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.telnyx.com/v2/iam/simulate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/iam/simulate")
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 \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"action": "number_order.create",
"decision": "allow",
"reason": "action_allowed",
"detail": "a role allows number_order.create",
"allowed_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"denied_role_ids": [],
"record_type": "iam_decision"
},
{
"action": "number.delete",
"decision": "deny",
"reason": "action_denied",
"detail": "a role denies number.delete",
"allowed_role_ids": [],
"denied_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"record_type": "iam_decision"
}
]
}Authorizations
Body
Was this page helpful?
curl --request POST \
--url https://api.telnyx.com/v2/iam/simulate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"principal_type": "user",
"principal_id": "b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13",
"with_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"requests": [
{
"action": "number_order.create"
},
{
"action": "number.delete"
}
]
}
'import requests
url = "https://api.telnyx.com/v2/iam/simulate"
payload = {
"principal_type": "user",
"principal_id": "b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13",
"with_role_ids": ["8c4a9715-0246-4c6f-9eca-390e13bd8af0"],
"requests": [{ "action": "number_order.create" }, { "action": "number.delete" }]
}
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({
principal_type: 'user',
principal_id: 'b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13',
with_role_ids: ['8c4a9715-0246-4c6f-9eca-390e13bd8af0'],
requests: [{action: 'number_order.create'}, {action: 'number.delete'}]
})
};
fetch('https://api.telnyx.com/v2/iam/simulate', 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.telnyx.com/v2/iam/simulate",
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([
'principal_type' => 'user',
'principal_id' => 'b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13',
'with_role_ids' => [
'8c4a9715-0246-4c6f-9eca-390e13bd8af0'
],
'requests' => [
[
'action' => 'number_order.create'
],
[
'action' => 'number.delete'
]
]
]),
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.telnyx.com/v2/iam/simulate"
payload := strings.NewReader("{\n \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\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.telnyx.com/v2/iam/simulate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/iam/simulate")
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 \"principal_type\": \"user\",\n \"principal_id\": \"b1d7e2c4-9a3f-4e58-8c61-0f2a7d5e9b13\",\n \"with_role_ids\": [\n \"8c4a9715-0246-4c6f-9eca-390e13bd8af0\"\n ],\n \"requests\": [\n {\n \"action\": \"number_order.create\"\n },\n {\n \"action\": \"number.delete\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"action": "number_order.create",
"decision": "allow",
"reason": "action_allowed",
"detail": "a role allows number_order.create",
"allowed_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"denied_role_ids": [],
"record_type": "iam_decision"
},
{
"action": "number.delete",
"decision": "deny",
"reason": "action_denied",
"detail": "a role denies number.delete",
"allowed_role_ids": [],
"denied_role_ids": [
"8c4a9715-0246-4c6f-9eca-390e13bd8af0"
],
"record_type": "iam_decision"
}
]
}