How to remove an attribute via Rest API

Hi I met some problem using Rest API.

/ip/firewall/filter
add action=accept chain=forward src-address-list=MyIPa protocal=tcp

I can change them via Rest API
curl -k -u admin: -X PATCH https://1.1.1.1/rest/ip/address/*3 --data ‘{“comment”: “test”}’ -H “content-type: application/json” {“.id”:“*3”,“src-address-list”:“MyIPb”}
with no problem.

But how can I remove this attribute, (NOT set them to src-address-list=“”), like below.
/ip/firewall/filter
add action=accept chain=forward protocal=tcp

TL;DR: you set the attribute to null (without quotes) in the JSON provided to curl.

But that’s may not your only problem. I think you’re confusing add and set, which are PUT and PATCH respectively in REST API. https://help.mikrotik.com/docs/spaces/ROS/pages/47579162/REST+API#RESTAPI-HTTPMethods

i.e.

  1. You show an “add” in CLI, but then use -X PATCH which is a CLI “set”.
  2. You show using --data and then have more JSON at end of curl. Perhaps curl “figures it out” (or perhaps not), but ALL JSON should be part of ONE --data — the JSON should NOT be split into two parts.

Now I suspect an LLM may have led you astray… I’d recommend reading the help at MikroTik which does have good curl examples.

Thanks for reply, and sorry for not describe clearly, I didn't confusing add and set :stuck_out_tongue:

My configure export is like....

/ip/firewall/filter
add action=accept chain=forward dst-address=1.1.1.1 protocol=tcp src-address-list=aaa

and I can change src-address-list=bbb using Rest API

curl -k -u admin:123456 -X PATCH https://router/rest/ip/firewall/filter/*40D --data '{"src-address-list": "bbb"}' -H "content-type: application/json"

after I change that, configure exported is like......... (that works fine)
/ip/firewall/filter
add action=accept chain=forward dst-address=1.1.1.1 protocol=tcp src-address-list=bbb

but I would like to remove src-address-list= attribute.

after that, configure exported should like.........
/ip/firewall/filter
add action=accept chain=forward dst-address=1.1.1.1 protocol=tcp

I tried......
curl -k -u admin:123456 -X PATCH https://router/rest/ip/firewall/filter/*40D --data '{"src-address-list": NULL}' -H "content-type: application/json"
response: {"detail":"Failed to parse json","error":400,"message":"Bad Request"}
curl -k -u admin:123456 -X PATCH https://router/rest/ip/firewall/filter/*40D --data '{"src-address-list": null}' -H "content-type: application/json"
response: {".id":"*40D","action":"accept","bytes":"18152","chain":"forward","disabled":"false","dst-address":"1.1.1.1","dynamic":"false","invalid":"false","log":"false","log-prefix":"","packets":"269","protocol":"tcp","src-address-list":""} (but src-address-list still unchanged)

I would like if anyone know how to remove an attribute using Restful API......

The “null” should have worked - but you’re right even in 7.20, you get “” which is NOT empty. But in most cases, POST let to replicate anything the CLI can do, so that’s the trick needed here…

So if you use a POST with “unset” instead, including in JSON of .id and value-name keys (which is “src-address-list”) that should remove it:

curl -k -u '$USER:$PASSWD' http://$ROUTERIP/rest/ip/firewall/filter/unset --json "{\".id\": \"$ROSID\", \"value-name\":\"src-address-list\"}"