Similar to add a new address-list entry, that’s also use PUT or POST:
-X PUT http://ip/rest/ip/firewall/address-list --json ‘{“address”: “127.0.0.42”, “list”: “mylist”}’ or
-X POST http://ip/rest/ip/firewall/address-list/add --json ‘{“address”: “127.0.0.42”, “list”: “mylist”}’
… Again POST uses the CLI keyword “add” while PUT infers that from HTTP method.
I should add that when using POST operations, the JSON can have a root of “ret:”, so if your looking for an array from the results in n8n you may need to add a .ret
Very strange, but I opened up postman this morning and hit run and what didn’t work yesterday (get address-list), works today. Everything works, postman and n8n’s http requester.
Well, that’s a more complex story. It may be helpful to think the REST API has TWO different APIs. One uses POST, which is an HTTP-proxy around the “binary” API https://help.mikrotik.com/docs/display/ROS/API … so for a HTTP-based REST POST request, the “where” manifests itself as { “.query”: [“list=myaddrlist”] } & support the RPN/stack-based filter in the JSON array but using “=” in the string based API-syntax – tricky business…
On a GET call, the “where” is more simple & just part of the URL in the query string. So on a GET ?list=myaddlist
And similar with PATCH where the .id (e.g. what shows as * in CLI print show-ids) is part of the path so PATCH (or “set”):
To pull the existing address lists via the Microtik API, you can use the following GET request:
GET /rest/ip/firewall/address-list
This request will return a list of all address lists on the router.
To match the existing address list against some other data, you can use the filter parameter. For example, the following request will return all address lists with a name that contains the string “my_address_list”:
GET /rest/ip/firewall/address-list?filter=name~my_address_list
To add, update, or delete entries in an address list, you can use the POST request for /rest/ip/firewall/address-list/print. The JSON body for this request should contain the following parameters:
name: The name of the address list.
add: A list of entries to add to the address list.
remove: A list of entries to remove from the address list.
set: A list of entries to update in the address list.
For example, the following request will add a new entry to the address list my_address_list:
POST /rest/ip/firewall/address-list/print
{
“name”: “my_address_list”,
“add”: [
{
“address”: “192.168.1.100/24”,
“comment”: “This is a new entry.”
}
]
}
You can use Postman for interactive queries and n8n to create a processing flow that automates your address list management tasks.
Here is an example of a n8n flow that pulls the existing address lists from the Microtik API and then matches them against some other data:
Set Data:
Variable: addressLists
Value: {{data}}
Else:
Throw Error:
Message: No address lists found.
You can then add additional nodes to the flow to match the address lists against some other data and to add, update, or delete entries in the address lists.