Create browser session
Creates an isolated browser session with network access restricted to the domains you allow.
POST
/
browser_sessions
Create browser session
curl --request POST \
--url https://api.telnyx.com/v2/browser_sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"policy": {
"allowed_domains": [
"example.com"
]
}
}
'import requests
url = "https://api.telnyx.com/v2/browser_sessions"
payload = { "policy": { "allowed_domains": ["example.com"] } }
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({policy: {allowed_domains: ['example.com']}})
};
fetch('https://api.telnyx.com/v2/browser_sessions', 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/browser_sessions",
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([
'policy' => [
'allowed_domains' => [
'example.com'
]
]
]),
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/browser_sessions"
payload := strings.NewReader("{\n \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\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/browser_sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/browser_sessions")
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 \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "bsess_3b108e10-906a-486e-9132-196726ba7979",
"status": "provisioning",
"failure_reason": "<string>",
"policy": {
"allowed_domains": [
"<string>"
]
},
"limits": {
"lifetime_s": 123,
"idle_timeout_s": 123
},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"ready_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"closed_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_error",
"message": "invalid request: policy.allowed_domains must have at least 1 item(s)",
"retryable": false
}
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request.",
"source": {
"pointer": "/"
},
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10009"
}
}
]
}{
"error": {
"code": "idempotency_conflict",
"message": "idempotency key reused with a different request",
"retryable": false
}
}{
"error": {
"code": "quota_exceeded",
"message": "organization concurrent-session limit reached",
"retryable": true
}
}{
"error": {
"code": "internal_error",
"message": "failed to provision browser session",
"retryable": true
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Arbitrary key-value metadata.
Scoped to the organization. The same key and identical normalized policy, limits, and metadata replay the existing session (HTTP 201); a different request returns 409 idempotency_conflict. Replays do not restart terminal sessions.
Required string length:
1 - 255Response
Session created
Show child attributes
Show child attributes
Was this page helpful?
Create browser session
curl --request POST \
--url https://api.telnyx.com/v2/browser_sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"policy": {
"allowed_domains": [
"example.com"
]
}
}
'import requests
url = "https://api.telnyx.com/v2/browser_sessions"
payload = { "policy": { "allowed_domains": ["example.com"] } }
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({policy: {allowed_domains: ['example.com']}})
};
fetch('https://api.telnyx.com/v2/browser_sessions', 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/browser_sessions",
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([
'policy' => [
'allowed_domains' => [
'example.com'
]
]
]),
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/browser_sessions"
payload := strings.NewReader("{\n \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\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/browser_sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/browser_sessions")
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 \"policy\": {\n \"allowed_domains\": [\n \"example.com\"\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "bsess_3b108e10-906a-486e-9132-196726ba7979",
"status": "provisioning",
"failure_reason": "<string>",
"policy": {
"allowed_domains": [
"<string>"
]
},
"limits": {
"lifetime_s": 123,
"idle_timeout_s": 123
},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"ready_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"closed_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_error",
"message": "invalid request: policy.allowed_domains must have at least 1 item(s)",
"retryable": false
}
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request.",
"source": {
"pointer": "/"
},
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10009"
}
}
]
}{
"error": {
"code": "idempotency_conflict",
"message": "idempotency key reused with a different request",
"retryable": false
}
}{
"error": {
"code": "quota_exceeded",
"message": "organization concurrent-session limit reached",
"retryable": true
}
}{
"error": {
"code": "internal_error",
"message": "failed to provision browser session",
"retryable": true
}
}