Create Network Policy
Create a network policy that allows or blocks domains for the browsers that reference it with networkPolicyId.
A domain such as example.com matches the domain and all of its subdomains, and the most specific entry wins. Domains are trimmed, lower-cased and converted to punycode, a trailing dot and a leading *. are removed, and duplicates are dropped. URLs, paths, ports, IP addresses, other wildcards and a domain in both lists are rejected. A policy has at most 10,000 domains, and a project has at most 100 policies.
POST
/
network-policies
Create Network Policy
const options = {
method: 'POST',
headers: {'X-Browser-Use-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
defaultAction: 'allow',
allow: {domains: ['<string>']},
block: {domains: ['<string>']}
})
};
fetch('https://api.browser-use.com/api/v4/network-policies', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://api.browser-use.com/api/v4/network-policies \
--header 'Content-Type: application/json' \
--header 'X-Browser-Use-API-Key: <api-key>' \
--data '
{
"name": "<string>",
"defaultAction": "allow",
"allow": {
"domains": [
"<string>"
]
},
"block": {
"domains": [
"<string>"
]
}
}
'import requests
url = "https://api.browser-use.com/api/v4/network-policies"
payload = {
"name": "<string>",
"defaultAction": "allow",
"allow": { "domains": ["<string>"] },
"block": { "domains": ["<string>"] }
}
headers = {
"X-Browser-Use-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"defaultAction": "allow",
"allow": {
"domains": [
"<string>"
]
},
"block": {
"domains": [
"<string>"
]
},
"version": 123,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Body
application/json
Request body for creating a network policy.
Response
Successful Response
A network policy with normalized domains.
Was this page helpful?
⌘I
Create Network Policy
const options = {
method: 'POST',
headers: {'X-Browser-Use-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
defaultAction: 'allow',
allow: {domains: ['<string>']},
block: {domains: ['<string>']}
})
};
fetch('https://api.browser-use.com/api/v4/network-policies', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://api.browser-use.com/api/v4/network-policies \
--header 'Content-Type: application/json' \
--header 'X-Browser-Use-API-Key: <api-key>' \
--data '
{
"name": "<string>",
"defaultAction": "allow",
"allow": {
"domains": [
"<string>"
]
},
"block": {
"domains": [
"<string>"
]
}
}
'import requests
url = "https://api.browser-use.com/api/v4/network-policies"
payload = {
"name": "<string>",
"defaultAction": "allow",
"allow": { "domains": ["<string>"] },
"block": { "domains": ["<string>"] }
}
headers = {
"X-Browser-Use-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"defaultAction": "allow",
"allow": {
"domains": [
"<string>"
]
},
"block": {
"domains": [
"<string>"
]
},
"version": 123,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}