MikrotikApi (mikrotik_api v0.3.4)

View Source

Public API for interacting with MikroTik RouterOS REST endpoints.

Usage pattern:

  • Establish an %MikrotikApi.Auth{} once.
  • Pass Auth and a target IP (IPv4/IPv6 literal) to each call.

Transport via OTP; JSON via Elixir's built-in JSON. Logging uses Logger only.

Summary

Functions

PUT /interface/bridge - create a bridge interface. RouterOS REST API uses PUT for creating resources.

DELETE /interface/bridge/{id}

Ensure a bridge exists by name. Returns {:ok, name} if found or created.

GET /interface/bridge

PUT /interface/bridge/port - create a bridge port. RouterOS REST API uses PUT for creating resources.

DELETE /interface/bridge/port/{id}

Ensure a bridge port exists for the given bridge and interface. Returns {:ok, {bridge, interface}} when found or created.

GET /interface/bridge/port

PATCH /interface/bridge/port/{id}

PATCH /interface/bridge/{id}

PUT /interface/bridge/vlan - create a bridge VLAN entry. RouterOS REST API uses PUT for creating resources.

DELETE /interface/bridge/vlan/{id}

Ensure a bridge VLAN entry exists for the given bridge and vlan-ids. Returns {:ok, {bridge, vlan_ids}} when found or created.

GET /interface/bridge/vlan

PATCH /interface/bridge/vlan/{id}

Generic call. See get/3, post/4, put/4, patch/4, delete/3. opts: :body (map or list), :params (map), :headers (list), :scheme (:https | :http), :port (integer)

PUT /caps-man/provisioning - create a CAPsMAN provisioning rule. RouterOS REST API uses PUT for creating resources.

Ensure a CAPsMAN provisioning rule exists. By default matches by ["action", "master-configuration"]. Returns {:ok, map()} of matched keys when found or created.

GET /caps-man/registration-table

PUT /caps-man/security - create a CAPsMAN security profile. RouterOS REST API uses PUT for creating resources.

Ensure a CAPsMAN security profile with the given name exists.

DELETE a path under /rest on the target.

PUT /ip/dhcp-server/lease - create a DHCP lease. RouterOS REST API uses PUT for creating resources.

DELETE /ip/dhcp-server/lease/{id}

Ensure a DHCP lease exists. Matches by ["address", "mac-address"]. Returns {:ok, %{address: ..., mac: ...}} if found or created.

GET /ip/dhcp-server/lease

PATCH /ip/dhcp-server/lease/{id}

POST /ip/dns/cache/flush - flush the DNS cache.

GET /ip/dns (config/stats)

GET /ip/dns - alias for dns_config for consistency with REST pattern.

POST /ip/dns/set - update DNS server settings.

PUT /ip/dns/static - create a DNS static record. RouterOS REST API uses PUT for creating resources.

DELETE /ip/dns/static/{id}

Ensure a DNS static record exists by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

Create a WireGuard interface on router A, then replicate its private key to router B.

GET /interface/eoip

GET /interface/ethernet/poe

GET /interface/ethernet/switch/port

GET /ip/firewall/address-list

PUT /ip/firewall/filter - create a firewall filter rule. RouterOS REST API uses PUT for creating resources.

DELETE /ip/firewall/filter/{id}

Ensure a firewall filter rule exists. By default, matches existing by ["chain", "action"]. You can pass unique_keys: [..] in opts to control matching. Returns {:ok, Map.t()} with the matched key-values when found or created.

PUT /ip/firewall/nat - create a firewall NAT rule. RouterOS REST API uses PUT for creating resources.

DELETE /ip/firewall/nat/{id}

Ensure a firewall NAT rule exists. By default matches by ["chain", "action"]. You can pass unique_keys: [..] in opts. Returns {:ok, map()} of matched keys when found or created.

GET a path under /rest on the target.

PUT /interface/gre - create a GRE interface. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/gre/add on older RouterOS versions.

DELETE /interface/gre/{id}

Ensure a GRE interface by name or .id. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

GET /interface/gre

Convenience: set disabled=yes

Convenience: set disabled=no

Ensure interface settings. Ident can be an interface name or .id. Applies only differing keys from attrs. Returns {:ok, %{id: id, name: name, changed: [keys]}} when up-to-date or updated; {:error, not_found} if interface not present.

GET /interface/ethernet/monitor/{ident}

PATCH /interface/{id} with attrs

PUT /ip/address - create an IP address. RouterOS REST API uses PUT for creating resources.

Ensure an IP address exists on an interface. Requires attrs to include at least "address" and optionally "interface"; matches existing entries by these keys. Returns {:ok, address} when found or created.

GET /interface/ipip

GET /ipv6/firewall/address-list

Execute the same REST call concurrently across multiple IPs.

PATCH JSON to a path under /rest on the target.

POST JSON to a path under /rest on the target.

Probe core device info and summarize.

Probe wireless (legacy) and wifi (wifiwave2) endpoint availability and summarize.

PUT JSON to a path under /rest on the target.

PUT /ip/route - create a route. RouterOS REST API uses PUT for creating resources.

Ensure a route exists. Matches by ["dst-address", "gateway"]. Returns {:ok, %{dst: ..., gw: ...}} if found or created.

GET /routing/bfd/session

GET /routing/bgp/session

POST /system/identity/set - update the system identity (router name).

PUT /user - create a new user. RouterOS REST API uses PUT for creating resources.

DELETE /user/{id} - delete a user by .id.

Ensure a user exists by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

PATCH /user/{id} - update a user by .id.

PUT /interface/wifi/security - create a WiFi security profile. RouterOS REST API uses PUT for creating resources.

DELETE /interface/wifi/security/{id}

Ensure a WiFi security profile with the given name exists; returns the found or created entry name. If the endpoint is unavailable, returns the underlying error.

GET /interface/wifi/security

PATCH /interface/wifi/security/{id}

PUT /interface/wifi/ssid - create a WiFi SSID. RouterOS REST API uses PUT for creating resources.

DELETE /interface/wifi/ssid/{id}

Ensure a WiFi SSID with the given name exists; returns the found or created entry name. If the endpoint is unavailable (:wifi_ssid_unavailable), returns the underlying error.

GET /interface/wifi/ssid

PATCH /interface/wifi/ssid/{id}

Create a WireGuard interface across a cluster of routers.

Add or update WireGuard peers across a cluster on an existing interface.

PUT /interface/wireguard - create a WireGuard interface. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/wireguard/add on older RouterOS versions.

DELETE /interface/wireguard/{id}

Ensure a WireGuard interface by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}} when up-to-date or updated; {:error, not_found} if list fails. Note: On create, the actual .id may not be known immediately; id will fallback to the provided name.

POST /interface/wireguard/getall with a .proplist to retrieve fields like private-key and public-key.

PUT /interface/wireguard/peers - create a WireGuard peer. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/wireguard/peers/add on older RouterOS versions.

DELETE /interface/wireguard/peers/{id}

Ensure a WireGuard peer identified by {interface, public-key} exists with desired attributes. Only differing keys are patched. Returns {:ok, %{id: id | public-key, interface: name, changed: [keys]}}.

GET /interface/wireguard/peers

PATCH /interface/wireguard/peers/{id}

PUT /interface/wireless - create a wireless interface. RouterOS REST API uses PUT for creating resources.

DELETE /interface/wireless/{id}

Ensure a legacy wireless interface exists by name.

GET /interface/wireless/registration-table

PUT /interface/wireless/security-profiles - create a wireless security profile. RouterOS REST API uses PUT for creating resources.

DELETE /interface/wireless/security-profiles/{id}

Ensure a legacy wireless security profile exists by name.

GET /interface/wireless/security-profiles

PATCH /interface/wireless/security-profiles/{id}

Types

method()

@type method() :: :get | :post | :put | :patch | :delete

Functions

arp_list(auth, ip, opts \\ [])

@spec arp_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/arp

bridge_add(auth, ip, attrs, opts \\ [])

@spec bridge_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/bridge - create a bridge interface. RouterOS REST API uses PUT for creating resources.

bridge_delete(auth, ip, id, opts \\ [])

@spec bridge_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/bridge/{id}

bridge_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec bridge_ensure(MikrotikApi.Auth.t(), String.t(), String.t(), map(), Keyword.t()) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a bridge exists by name. Returns {:ok, name} if found or created.

bridge_list(auth, ip, opts \\ [])

@spec bridge_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/bridge

bridge_port_add(auth, ip, attrs, opts \\ [])

@spec bridge_port_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/bridge/port - create a bridge port. RouterOS REST API uses PUT for creating resources.

bridge_port_delete(auth, ip, id, opts \\ [])

@spec bridge_port_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/bridge/port/{id}

bridge_port_ensure(auth, ip, bridge, interface, attrs \\ %{}, opts \\ [])

@spec bridge_port_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, {String.t(), String.t()}} | {:error, MikrotikApi.Error.t()}

Ensure a bridge port exists for the given bridge and interface. Returns {:ok, {bridge, interface}} when found or created.

bridge_port_list(auth, ip, opts \\ [])

@spec bridge_port_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/bridge/port

bridge_port_update(auth, ip, id, attrs, opts \\ [])

@spec bridge_port_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/bridge/port/{id}

bridge_update(auth, ip, id, attrs, opts \\ [])

@spec bridge_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/bridge/{id}

bridge_vlan_add(auth, ip, attrs, opts \\ [])

@spec bridge_vlan_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/bridge/vlan - create a bridge VLAN entry. RouterOS REST API uses PUT for creating resources.

bridge_vlan_delete(auth, ip, id, opts \\ [])

@spec bridge_vlan_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/bridge/vlan/{id}

bridge_vlan_ensure(auth, ip, bridge, vlan_ids, attrs \\ %{}, opts \\ [])

@spec bridge_vlan_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, {String.t(), String.t()}} | {:error, MikrotikApi.Error.t()}

Ensure a bridge VLAN entry exists for the given bridge and vlan-ids. Returns {:ok, {bridge, vlan_ids}} when found or created.

bridge_vlan_list(auth, ip, opts \\ [])

@spec bridge_vlan_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/bridge/vlan

bridge_vlan_update(auth, ip, id, attrs, opts \\ [])

@spec bridge_vlan_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/bridge/vlan/{id}

call(auth, ip, method, path, opts \\ [])

@spec call(MikrotikApi.Auth.t(), String.t(), method(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

Generic call. See get/3, post/4, put/4, patch/4, delete/3. opts: :body (map or list), :params (map), :headers (list), :scheme (:https | :http), :port (integer)

capsman_interface_list(auth, ip, opts \\ [])

@spec capsman_interface_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /caps-man/interface

capsman_provisioning_add(auth, ip, attrs, opts \\ [])

@spec capsman_provisioning_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /caps-man/provisioning - create a CAPsMAN provisioning rule. RouterOS REST API uses PUT for creating resources.

capsman_provisioning_ensure(auth, ip, rule, opts \\ [])

@spec capsman_provisioning_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Ensure a CAPsMAN provisioning rule exists. By default matches by ["action", "master-configuration"]. Returns {:ok, map()} of matched keys when found or created.

capsman_provisioning_list(auth, ip, opts \\ [])

@spec capsman_provisioning_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /caps-man/provisioning

capsman_registration_table(auth, ip, opts \\ [])

@spec capsman_registration_table(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /caps-man/registration-table

capsman_security_add(auth, ip, attrs, opts \\ [])

@spec capsman_security_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /caps-man/security - create a CAPsMAN security profile. RouterOS REST API uses PUT for creating resources.

capsman_security_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec capsman_security_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a CAPsMAN security profile with the given name exists.

capsman_security_list(auth, ip, opts \\ [])

@spec capsman_security_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /caps-man/security

certificate_list(auth, ip, opts \\ [])

@spec certificate_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /certificate

container_list(auth, ip, opts \\ [])

@spec container_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /container

delete(auth, ip, path, opts \\ [])

@spec delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE a path under /rest on the target.

dhcp_lease_add(auth, ip, attrs, opts \\ [])

@spec dhcp_lease_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/dhcp-server/lease - create a DHCP lease. RouterOS REST API uses PUT for creating resources.

dhcp_lease_delete(auth, ip, id, opts \\ [])

@spec dhcp_lease_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/dhcp-server/lease/{id}

dhcp_lease_ensure(auth, ip, attrs, opts \\ [])

@spec dhcp_lease_ensure(MikrotikApi.Auth.t(), String.t(), map(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Ensure a DHCP lease exists. Matches by ["address", "mac-address"]. Returns {:ok, %{address: ..., mac: ...}} if found or created.

dhcp_lease_list(auth, ip, opts \\ [])

@spec dhcp_lease_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/dhcp-server/lease

dhcp_lease_update(auth, ip, id, attrs, opts \\ [])

@spec dhcp_lease_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /ip/dhcp-server/lease/{id}

dns_cache_flush(auth, ip, opts \\ [])

@spec dns_cache_flush(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

POST /ip/dns/cache/flush - flush the DNS cache.

dns_cache_list(auth, ip, opts \\ [])

@spec dns_cache_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/dns/cache

dns_config(auth, ip, opts \\ [])

@spec dns_config(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/dns (config/stats)

dns_settings_get(auth, ip, opts \\ [])

@spec dns_settings_get(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/dns - alias for dns_config for consistency with REST pattern.

dns_settings_set(auth, ip, attrs, opts \\ [])

@spec dns_settings_set(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

POST /ip/dns/set - update DNS server settings.

dns_static_add(auth, ip, attrs, opts \\ [])

@spec dns_static_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/dns/static - create a DNS static record. RouterOS REST API uses PUT for creating resources.

dns_static_delete(auth, ip, id, opts \\ [])

@spec dns_static_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/dns/static/{id}

dns_static_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec dns_static_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, %{id: String.t(), name: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure a DNS static record exists by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

dns_static_list(auth, ip, opts \\ [])

@spec dns_static_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/dns/static

dns_static_update(auth, ip, id, attrs, opts \\ [])

@spec dns_static_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /ip/dns/static/{id}

ensure_wireguard_pair(auth, ip_a, name_a, ip_b, name_b, attrs \\ %{}, opts \\ [])

@spec ensure_wireguard_pair(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) :: {:ok, %{a: map(), b: map()}} | {:error, MikrotikApi.Error.t() | term()}

Create a WireGuard interface on router A, then replicate its private key to router B.

Sequential steps (no concurrency):

  1. Ensure interface on A with provided attrs (RouterOS may generate private-key).
  2. Read back interface list on A; locate the entry by name and extract "private-key".
    • If not present, returns {:error, %MikrotikApi.Error{reason: :wireguard_private_key_unreadable}}.
  3. Ensure interface on B with the same "private-key" plus provided attrs.

Security: Never logs the private key. The returned value does not include the key.

eoip_list(auth, ip, opts \\ [])

@spec eoip_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/eoip

ethernet_poe_list(auth, ip, opts \\ [])

@spec ethernet_poe_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/ethernet/poe

ethernet_switch_port_list(auth, ip, opts \\ [])

@spec ethernet_switch_port_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/ethernet/switch/port

firewall_address_list(auth, ip, opts \\ [])

@spec firewall_address_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/firewall/address-list

firewall_connection_list(auth, ip, opts \\ [])

@spec firewall_connection_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/firewall/connection

firewall_filter_add(auth, ip, rule, opts \\ [])

@spec firewall_filter_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/firewall/filter - create a firewall filter rule. RouterOS REST API uses PUT for creating resources.

firewall_filter_delete(auth, ip, id, opts \\ [])

@spec firewall_filter_delete(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/firewall/filter/{id}

firewall_filter_ensure(auth, ip, rule, opts \\ [])

@spec firewall_filter_ensure(MikrotikApi.Auth.t(), String.t(), map(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Ensure a firewall filter rule exists. By default, matches existing by ["chain", "action"]. You can pass unique_keys: [..] in opts to control matching. Returns {:ok, Map.t()} with the matched key-values when found or created.

firewall_filter_list(auth, ip, opts \\ [])

@spec firewall_filter_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/firewall/filter

firewall_nat_add(auth, ip, rule, opts \\ [])

@spec firewall_nat_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/firewall/nat - create a firewall NAT rule. RouterOS REST API uses PUT for creating resources.

firewall_nat_delete(auth, ip, id, opts \\ [])

@spec firewall_nat_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/firewall/nat/{id}

firewall_nat_ensure(auth, ip, rule, opts \\ [])

@spec firewall_nat_ensure(MikrotikApi.Auth.t(), String.t(), map(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Ensure a firewall NAT rule exists. By default matches by ["chain", "action"]. You can pass unique_keys: [..] in opts. Returns {:ok, map()} of matched keys when found or created.

firewall_nat_list(auth, ip, opts \\ [])

@spec firewall_nat_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/firewall/nat

get(auth, ip, path, opts \\ [])

@spec get(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET a path under /rest on the target.

gre_add(auth, ip, attrs, opts \\ [])

@spec gre_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/gre - create a GRE interface. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/gre/add on older RouterOS versions.

gre_delete(auth, ip, id, opts \\ [])

@spec gre_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/gre/{id}

gre_ensure(auth, ip, ident, attrs \\ %{}, opts \\ [])

@spec gre_ensure(MikrotikApi.Auth.t(), String.t(), String.t(), map(), Keyword.t()) ::
  {:ok, %{id: String.t(), name: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure a GRE interface by name or .id. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

gre_list(auth, ip, opts \\ [])

@spec gre_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/gre

gre_update(auth, ip, id, attrs, opts \\ [])

@spec gre_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/gre/{id}

interface_disable(auth, ip, id, opts \\ [])

@spec interface_disable(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

Convenience: set disabled=yes

interface_enable(auth, ip, id, opts \\ [])

@spec interface_enable(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

Convenience: set disabled=no

interface_ensure(auth, ip, ident, attrs, opts \\ [])

@spec interface_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, %{id: String.t(), name: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure interface settings. Ident can be an interface name or .id. Applies only differing keys from attrs. Returns {:ok, %{id: id, name: name, changed: [keys]}} when up-to-date or updated; {:error, not_found} if interface not present.

interface_ethernet_monitor(auth, ip, ident, opts \\ [])

@spec interface_ethernet_monitor(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/ethernet/monitor/{ident}

interface_list(auth, ip, opts \\ [])

@spec interface_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface

interface_update(auth, ip, id, attrs, opts \\ [])

@spec interface_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/{id} with attrs

ip_address_add(auth, ip, attrs, opts \\ [])

@spec ip_address_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/address - create an IP address. RouterOS REST API uses PUT for creating resources.

ip_address_delete(auth, ip, id, opts \\ [])

@spec ip_address_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/address/{id}

ip_address_ensure(auth, ip, attrs, opts \\ [])

@spec ip_address_ensure(MikrotikApi.Auth.t(), String.t(), map(), Keyword.t()) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure an IP address exists on an interface. Requires attrs to include at least "address" and optionally "interface"; matches existing entries by these keys. Returns {:ok, address} when found or created.

ip_address_list(auth, ip, opts \\ [])

@spec ip_address_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/address

ip_address_update(auth, ip, id, attrs, opts \\ [])

@spec ip_address_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /ip/address/{id}

ip_cloud_info(auth, ip, opts \\ [])

@spec ip_cloud_info(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/cloud

ip_pool_list(auth, ip, opts \\ [])

@spec ip_pool_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/pool

ipip_list(auth, ip, opts \\ [])

@spec ipip_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/ipip

ipv6_firewall_address_list(auth, ip, opts \\ [])

@spec ipv6_firewall_address_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ipv6/firewall/address-list

ipv6_firewall_filter_list(auth, ip, opts \\ [])

@spec ipv6_firewall_filter_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ipv6/firewall/filter

ipv6_neighbor_list(auth, ip, opts \\ [])

@spec ipv6_neighbor_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ipv6/neighbor

ipv6_pool_list(auth, ip, opts \\ [])

@spec ipv6_pool_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ipv6/pool

ipv6_route_list(auth, ip, opts \\ [])

@spec ipv6_route_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ipv6/route

multi(auth, ips, method, path, opts \\ [], stream_opts \\ [])

@spec multi(
  MikrotikApi.Auth.t(),
  [String.t()],
  method(),
  String.t(),
  Keyword.t(),
  Keyword.t()
) :: [
  %{
    ip: String.t(),
    result: {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}
  }
]

Execute the same REST call concurrently across multiple IPs.

  • ips: list of target IPs (IPv4/IPv6 as strings)
  • method: :get | :post | :put | :patch | :delete

  • path: string path under /rest (e.g., "/system/resource")
  • opts: keyword options accepted by call/5 (e.g., scheme:, decode:, params:, headers:, body: for write methods)
  • stream_opts:
    • :max_concurrency (default System.schedulers_online())
    • :timeout (default 15_000 ms)

Returns a list in input order: [%{ip: ip, result: {:ok, value} | {:error, %MikrotikApi.Error{}}}]

neighbor_list(auth, ip, opts \\ [])

@spec neighbor_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/neighbor

patch(auth, ip, path, body, opts \\ [])

@spec patch(MikrotikApi.Auth.t(), String.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH JSON to a path under /rest on the target.

post(auth, ip, path, body \\ nil, opts \\ [])

@spec post(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list() | nil,
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

POST JSON to a path under /rest on the target.

probe_device(auth, ip, opts \\ [])

@spec probe_device(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Probe core device info and summarize.

Returns a map with keys:

  • system: {:ok, map()} | {:error, error_summary}

  • counts: %{interfaces: n | nil, ip_addresses: n | nil, arp: n | nil, neighbors: n | nil}

Accepts same opts as other calls (e.g., scheme: :http | :https).

probe_wireless(auth, ip, opts \\ [])

@spec probe_wireless(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Probe wireless (legacy) and wifi (wifiwave2) endpoint availability and summarize.

Returns a map with sections :wireless and :wifi, each containing endpoint keys and status maps like %{status: :ok | :unavailable | :error, count: non_neg_integer | nil, reason: term() | nil, status_code: integer | nil}.

Accepts the same opts as other calls (e.g., scheme: :http | :https).

put(auth, ip, path, body, opts \\ [])

@spec put(MikrotikApi.Auth.t(), String.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT JSON to a path under /rest on the target.

queue_simple_list(auth, ip, opts \\ [])

@spec queue_simple_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /queue/simple

queue_tree_list(auth, ip, opts \\ [])

@spec queue_tree_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /queue/tree

route_add(auth, ip, attrs, opts \\ [])

@spec route_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /ip/route - create a route. RouterOS REST API uses PUT for creating resources.

route_delete(auth, ip, id, opts \\ [])

@spec route_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /ip/route/{id}

route_ensure(auth, ip, attrs, opts \\ [])

@spec route_ensure(MikrotikApi.Auth.t(), String.t(), map(), Keyword.t()) ::
  {:ok, map()} | {:error, MikrotikApi.Error.t()}

Ensure a route exists. Matches by ["dst-address", "gateway"]. Returns {:ok, %{dst: ..., gw: ...}} if found or created.

route_list(auth, ip, opts \\ [])

@spec route_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /ip/route

routing_bfd_list(auth, ip, opts \\ [])

@spec routing_bfd_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /routing/bfd/session

routing_bgp_list(auth, ip, opts \\ [])

@spec routing_bgp_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /routing/bgp/session

routing_stats(auth, ip, opts \\ [])

@spec routing_stats(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /routing/stats

system_health(auth, ip, opts \\ [])

@spec system_health(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /system/health

system_identity(auth, ip, opts \\ [])

@spec system_identity(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /system/identity

system_identity_set(auth, ip, name, opts \\ [])

@spec system_identity_set(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

POST /system/identity/set - update the system identity (router name).

system_packages(auth, ip, opts \\ [])

@spec system_packages(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /system/package

system_resource(auth, ip, opts \\ [])

@spec system_resource(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /system/resource

tool_netwatch_list(auth, ip, opts \\ [])

@spec tool_netwatch_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /tool/netwatch

user_active_list(auth, ip, opts \\ [])

@spec user_active_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /user/active

user_add(auth, ip, attrs, opts \\ [])

@spec user_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /user - create a new user. RouterOS REST API uses PUT for creating resources.

user_delete(auth, ip, id, opts \\ [])

@spec user_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /user/{id} - delete a user by .id.

user_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec user_ensure(MikrotikApi.Auth.t(), String.t(), String.t(), map(), Keyword.t()) ::
  {:ok, %{id: String.t(), name: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure a user exists by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}}.

user_group_list(auth, ip, opts \\ [])

@spec user_group_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /user/group

user_list(auth, ip, opts \\ [])

@spec user_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /user

user_update(auth, ip, id, attrs, opts \\ [])

@spec user_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /user/{id} - update a user by .id.

wifi_interface_list(auth, ip, opts \\ [])

@spec wifi_interface_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wifi

wifi_interface_update(auth, ip, id, attrs, opts \\ [])

@spec wifi_interface_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wifi/{id}

wifi_security_add(auth, ip, attrs, opts \\ [])

@spec wifi_security_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wifi/security - create a WiFi security profile. RouterOS REST API uses PUT for creating resources.

wifi_security_delete(auth, ip, id, opts \\ [])

@spec wifi_security_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wifi/security/{id}

wifi_security_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec wifi_security_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a WiFi security profile with the given name exists; returns the found or created entry name. If the endpoint is unavailable, returns the underlying error.

wifi_security_list(auth, ip, opts \\ [])

@spec wifi_security_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wifi/security

wifi_security_update(auth, ip, id, attrs, opts \\ [])

@spec wifi_security_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wifi/security/{id}

wifi_ssid_add(auth, ip, attrs, opts \\ [])

@spec wifi_ssid_add(MikrotikApi.Auth.t(), String.t(), map() | list(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wifi/ssid - create a WiFi SSID. RouterOS REST API uses PUT for creating resources.

wifi_ssid_delete(auth, ip, id, opts \\ [])

@spec wifi_ssid_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wifi/ssid/{id}

wifi_ssid_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec wifi_ssid_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a WiFi SSID with the given name exists; returns the found or created entry name. If the endpoint is unavailable (:wifi_ssid_unavailable), returns the underlying error.

wifi_ssid_list(auth, ip, opts \\ [])

@spec wifi_ssid_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wifi/ssid

wifi_ssid_update(auth, ip, id, attrs, opts \\ [])

@spec wifi_ssid_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wifi/ssid/{id}

wireguard_cluster_add(auth, ips, name, attrs \\ %{}, opts \\ [])

@spec wireguard_cluster_add(
  MikrotikApi.Auth.t(),
  [String.t()],
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok,
   %{
     primary: %{ip: String.t(), result: map()},
     members: [
       %{ip: String.t(), result: {:ok, map()} | {:error, MikrotikApi.Error.t()}}
     ],
     public_key: String.t()
   }}
  | {:error, MikrotikApi.Error.t() | term()}

Create a WireGuard interface across a cluster of routers.

Workflow:

  • Choose the first router in the list as the primary (key source).
  • Ensure the interface on the primary WITHOUT sending a private-key (allow RouterOS to auto-generate).
  • Retrieve the private-key (and public-key) from the primary; falls back to getall if list omits it.
  • Ensure the interface with the same private-key on all other routers concurrently.

Returns {:ok, %{primary: %{ip: ip, result: map()}, members: [%{ip: ip, result: {:ok, map()} | {:error, %MikrotikApi.Error{}}}], public_key: String.t()}} on success.

wireguard_cluster_add_peers(auth, ips, name, peers, opts \\ [])

@spec wireguard_cluster_add_peers(
  MikrotikApi.Auth.t(),
  [String.t()],
  String.t(),
  [map()],
  Keyword.t()
) ::
  {:ok,
   [
     %{
       ip: String.t(),
       results: [ok: map(), error: MikrotikApi.Error.t() | term()]
     }
   ]}

Add or update WireGuard peers across a cluster on an existing interface.

  • ips: list of router IPs (all members to apply peers to)
  • name: wireguard interface name (e.g., "wg0"); will be set on each peer attrs
  • peers: list of peer maps, each requiring at least "public-key"; optional keys include "allowed-address", "endpoint-address", "endpoint-port", "persistent-keepalive", etc.

Returns {:ok, [%{ip: ip, results: [result_per_peer]}]}.

wireguard_interface_add(auth, ip, attrs, opts \\ [])

@spec wireguard_interface_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wireguard - create a WireGuard interface. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/wireguard/add on older RouterOS versions.

wireguard_interface_delete(auth, ip, id, opts \\ [])

@spec wireguard_interface_delete(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wireguard/{id}

wireguard_interface_ensure(auth, ip, ident, attrs \\ %{}, opts \\ [])

@spec wireguard_interface_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, %{id: String.t(), name: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure a WireGuard interface by name. If present, patches only differing keys. Returns {:ok, %{id: id | name, name: name, changed: [keys]}} when up-to-date or updated; {:error, not_found} if list fails. Note: On create, the actual .id may not be known immediately; id will fallback to the provided name.

wireguard_interface_getall(auth, ip, proplist \\ "name,private-key,public-key", opts \\ [])

@spec wireguard_interface_getall(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, [map()]} | {:error, MikrotikApi.Error.t()}

POST /interface/wireguard/getall with a .proplist to retrieve fields like private-key and public-key.

wireguard_interface_list(auth, ip, opts \\ [])

@spec wireguard_interface_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wireguard

wireguard_interface_update(auth, ip, id, attrs, opts \\ [])

@spec wireguard_interface_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) :: {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wireguard/{id}

wireguard_peer_add(auth, ip, attrs, opts \\ [])

@spec wireguard_peer_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wireguard/peers - create a WireGuard peer. RouterOS REST API uses PUT for creating resources. Falls back to POST /interface/wireguard/peers/add on older RouterOS versions.

wireguard_peer_delete(auth, ip, id, opts \\ [])

@spec wireguard_peer_delete(MikrotikApi.Auth.t(), String.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wireguard/peers/{id}

wireguard_peer_ensure(auth, ip, interface, public_key, attrs \\ %{}, opts \\ [])

@spec wireguard_peer_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, %{id: String.t() | nil, interface: String.t(), changed: [String.t()]}}
  | {:error, term()}

Ensure a WireGuard peer identified by {interface, public-key} exists with desired attributes. Only differing keys are patched. Returns {:ok, %{id: id | public-key, interface: name, changed: [keys]}}.

wireguard_peer_list(auth, ip, opts \\ [])

@spec wireguard_peer_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wireguard/peers

wireguard_peer_update(auth, ip, id, attrs, opts \\ [])

@spec wireguard_peer_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wireguard/peers/{id}

wireless_interface_add(auth, ip, attrs, opts \\ [])

@spec wireless_interface_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wireless - create a wireless interface. RouterOS REST API uses PUT for creating resources.

wireless_interface_delete(auth, ip, id, opts \\ [])

@spec wireless_interface_delete(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wireless/{id}

wireless_interface_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec wireless_interface_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a legacy wireless interface exists by name.

wireless_interface_list(auth, ip, opts \\ [])

@spec wireless_interface_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wireless

wireless_interface_update(auth, ip, id, attrs, opts \\ [])

@spec wireless_interface_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) :: {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wireless/{id}

wireless_registration_table(auth, ip, opts \\ [])

@spec wireless_registration_table(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wireless/registration-table

wireless_security_profile_add(auth, ip, attrs, opts \\ [])

@spec wireless_security_profile_add(
  MikrotikApi.Auth.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PUT /interface/wireless/security-profiles - create a wireless security profile. RouterOS REST API uses PUT for creating resources.

wireless_security_profile_delete(auth, ip, id, opts \\ [])

@spec wireless_security_profile_delete(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  Keyword.t()
) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

DELETE /interface/wireless/security-profiles/{id}

wireless_security_profile_ensure(auth, ip, name, attrs \\ %{}, opts \\ [])

@spec wireless_security_profile_ensure(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map(),
  Keyword.t()
) ::
  {:ok, String.t()} | {:error, MikrotikApi.Error.t()}

Ensure a legacy wireless security profile exists by name.

wireless_security_profile_list(auth, ip, opts \\ [])

@spec wireless_security_profile_list(MikrotikApi.Auth.t(), String.t(), Keyword.t()) ::
  {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

GET /interface/wireless/security-profiles

wireless_security_profile_update(auth, ip, id, attrs, opts \\ [])

@spec wireless_security_profile_update(
  MikrotikApi.Auth.t(),
  String.t(),
  String.t(),
  map() | list(),
  Keyword.t()
) :: {:ok, any() | nil} | {:error, MikrotikApi.Error.t()}

PATCH /interface/wireless/security-profiles/{id}