create_traffic_rule
create_traffic_rule
Section titled “create_traffic_rule”Create a v2 traffic rule from a full rule object.
Side effects:
- Adds a new app/domain/IP allow-or-block policy that takes effect immediately on matching traffic.
- Mutates controller state. Use dry_run=True to preview the change without applying.
The v2 traffic-rule schema is rich and version-dependent, so this tool
takes the full rule object as a dict rather than fixed parameters.
Build it from a get_traffic_rule_details example on a similar rule,
or from the UniFi UI’s network inspector.
Example
Section titled “Example”create_traffic_rule(rule={"action": "BLOCK", "matching_target": "INTERNET", "target_devices": [], "enabled": True})Parameters
Section titled “Parameters”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
rule | object | yes | — | The full traffic-rule object. Common keys: action ("BLOCK"/"ALLOW"), matching_target ("INTERNET"/"DOMAIN"/"IP"/"REGION" etc.), target_devices (list), enabled (bool), and the target-specific fields (domains, ip_addresses, app_ids, regions) for the chosen matching_target. |
controller | string | no | ”default” | Name of the UniFi controller to target. Defaults to "default". |
dry_run | boolean | no | false | Preview the change without applying it. Returns the predicted change set. |