API help needed to disable/enable access rule
I have a nsa 4700 and am trying to write a simple script using curl to disable an access rule using the api. I wish to be able to schedule through my windows tack scheduler to turn on and off an access rule on specific days during the year. Here is the line I need help on:
curl -X PUT "https://192.168.168.168/api/sonicos/access-rules/ipv4" -H "accept: application/json" -H "Content-Type: application/json" -d "{"access_rules": [{ "ipv4": {"uuid": "00000000-0000-0016-0700-18c2416807fb", "enable": false}}]}"
This line executes with no errors, but when I commit the changes it deletes all of my custom access rules. Have I just missed something in the syntax?
Admittedly I am a newby with api.
Answers
Hi Y2kman,
I can confirm that the API has some inconsistencies. It's better with Gen 7. But still room for improvement. In your case I would suggest to use the API endpoint that accepts the UUID as path variable to avoid the deletion of all access rules.
https://{IP}:{PORT}/api/sonicos/access-rules/ipv4/uuid/{UUID}
The following json content works with a TZ470 running SonicOS 7.1.x:
{ "access_rules": [ { "ipv4": { "action": "allow", "enable":
false
, "comment": "test123" } } ]}