Skip to content

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.

create_traffic_rule(rule={"action": "BLOCK", "matching_target": "INTERNET", "target_devices": [], "enabled": True})
ParameterTypeRequiredDefaultDescription
ruleobjectyesThe 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.
controllerstringno”default”Name of the UniFi controller to target. Defaults to "default".
dry_runbooleannofalsePreview the change without applying it. Returns the predicted change set.