Skip to main content
pablo_embasa
Visitor III
Apr 25, 2022 2:18 PM UTC
Solved

Fortigate API - Remove address from group address

Hi,

I´m tring to integrate my Fortigates with an script.

My script can add any already created address in an specific group, but I can´t find a way to remove only one address, all I can use is add just an address or change all adresses all at once. 

Any help would be appraciented.

pminarik
pminarikAnswer
Staff
Apr 26, 2022 9:15 PM UTC

Hi pablo_embasa,

There's a neat little trick to this. You can directly target array-like keys in an object with POST requests to append to them, or directly do a DELETE request on one of the items in the array. Example below:

 

1, Get current members of an address group named "test_group":

GET /api/v2/cmdb/firewall/addrgrp/test_group

=> addr_1, addr_2, addr_3 (to keep this short, I am showing just the members after the command is run, not the actual JSON output)

 

2, Append a new address object to it:

POST /api/v2/cmdb/firewall/addrgrp/test_group/member

payload: {"name": "addr_4"}

=> addr_1, addr_2, addr_3, addr_4

 

3, Remove a single address object from it, but leave the rest:
DELETE /api/v2/cmdb/firewall/addrgrp/test_group/member/addr_2

=> addr_1, addr_3, addr_4

6 replies

Debbie_FTNT
Staff & Editor
Staff & Editor
Apr 25, 2022 2:44 PM UTC

Hey Pablo,

if I remember correctly, you can update the address group (including the member fields) with an HTTP PUT request.

I believe an HTTP put with '"member":[<array of all addresses except the one you want to remove>]' should do it.
You could do a GET request to have the addressgroup object, copy&paste the data, remove the address you want, and then send back with PUT request.

pablo_embasa
Visitor III
Apr 25, 2022 4:50 PM UTC

I know that I can do this, but the software that I´m using doesn´t permit any kind of algorithm, it only supports an API call, so it needs to be on only one request.

pminarik
Staff
pminarikAnswer
Staff
Apr 26, 2022 9:15 PM UTC

Hi pablo_embasa,

There's a neat little trick to this. You can directly target array-like keys in an object with POST requests to append to them, or directly do a DELETE request on one of the items in the array. Example below:

 

1, Get current members of an address group named "test_group":

GET /api/v2/cmdb/firewall/addrgrp/test_group

=> addr_1, addr_2, addr_3 (to keep this short, I am showing just the members after the command is run, not the actual JSON output)

 

2, Append a new address object to it:

POST /api/v2/cmdb/firewall/addrgrp/test_group/member

payload: {"name": "addr_4"}

=> addr_1, addr_2, addr_3, addr_4

 

3, Remove a single address object from it, but leave the rest:
DELETE /api/v2/cmdb/firewall/addrgrp/test_group/member/addr_2

=> addr_1, addr_3, addr_4

itlec
Explorer
Jun 5, 2024 7:09 PM UTC

Was wondering if one can create New Web Content Filter using a FortiOS REST API POST call.

pminarik
Staff
Staff
Jun 6, 2024 7:00 AM UTC

Yes, I've just tested this and you can do a POST request to: 

/api/v2/cmdb/webfilter/content/<id>/entries

With the new entry's payload:

{"name": "new block item",

"action": "block",

"status": "enable"}

 

The result will be an addition to the existing list of entries.

 

The only difficulty is identifying the right content-filter table ID. If your code doesn't know in advance, you'll need to do a GET request for the relevant webfilter profile first to identify the content-filter's ID. (the same situation applies to static URL filter lists)

pablo_embasa
Visitor III
Apr 28, 2022 10:46 AM UTC

Thanks, it works perfectly

Risk and Resilience in the Age of AI. An OT Thought Leadership Summit for Houston's Critical Infrastructure Leaders. Date: Thursday, December 3, 2026. Time: 8:30 am - 1:30 pm (CT). Location: The Westin Houston, Memorial City | 945 Gessner Road, Houston, TX 77024