Skip to main content
GeorgeFLopes
Visitor III
March 26, 2024
Solved

FortiOS API - addgrp

  • March 26, 2024
  • 5 replies
  • 2850 views

Hello,

 

Could someone give me one help?

 

Made this request to my fortinet, gives 200 but looking at console, not works.

 

curl -k -X PUT --location "https://*****/api/v2/cmdb/firewall/addrgrp/OFF" \
--insecure \
-H "Authorization: Bearer ****" \
--header 'Content-Type: application/json' \
--request PUT \
--data-raw '
{
"method": "PUT",
"url": "/api/v2/cmdb/firewall/addrgrp/OFF",
"params": {
"datasource": true,
"with_meta": true,
"vdom": "root"
},
"data": {
"member": [
{
"name": "X.X.X.1"
}
]
}
}'
{
"http_method":"PUT",
"revision":"519**",
"revision_changed":false,
"mkey":"TAOFF",
"status":"success",
"http_status":200,
"vdom":"root",
"path":"firewall",
"name":"addrgrp",
"serial":"FG*",
"version":"v7.4.3",
"build":2573
}%

Best answer by GeorgeFLopes

This worked for me, thx

 

curl --location "https://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member" --insecure -H "Authorization: Bearer **********" --header 'Content-Type: application/json' --request POST --data-raw '

{"name":"10.10.10.10"}

'

 

curl --location "https://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member/10.10.10.10" --insecure -H "Authorization: Bearer ****" --header 'Content-Type: application/json' --request DELETE

 

curl --location "hhttps://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member/" --insecure -H "Authorization: Bearer ****" --header 'Content-Type: application/json' --request GET

5 replies

rtanagras
Staff & Editor
Staff & Editor
March 26, 2024

Hi @GeorgeFLopes - can you try this CURL command?

curl -k --location "https://******/api/v2/cmdb/firewall/addrgrp/OFF" \
--insecure \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
--data-raw '{
"method": "PUT",
"params": {
"datasource": true,
"with_meta": true,
"vdom": "root"
},
"data": {
"member": [
{
"name": "X.X.X.1"
}
]
}
}'

just replace ****** with your actual URL and *** with your actual Authorization token.

GeorgeFLopes
Visitor III
March 26, 2024

Hey, Sure,

 
Output
  "status":"error",
  "http_status":405,
  "path":"firewall",
  "name":"addrgrp",
  "mkey":"OFF",
  "serial":"FGT*****",
  "version":"v7.4.3",
  "build":2573,
  "http_method":"POST"
rtanagras
Staff & Editor
Staff & Editor
March 26, 2024

Hi @GeorgeFLopes - Before you run the commands again, did you remove the existing members of your OFF address group?

 

You can check by using 'show firewall addrgrp | grep OFF'.

 

The PUT method is used to update or modify an existing address group. If you want to create a new one, use POST. To better understand the behavior of modifying an existing address group, try clicking on API Preview or inspecting your browser before clicking the OK button. You can also use 'httpsd -1' to see its behavior.

Here, maybe this link would help you: https://community.fortinet.com/t5/Support-Forum/Fortigate-API-Remove-address-from-group-address/m-p/210541#M192910

ozkanaltas
Valued Contributor III
March 26, 2024

Hello @GeorgeFLopes ,

 

Can you try like this.Without "data"

 

{     "member": [       {         "name": "xxx_user_name"       }     ]   } }

 

GeorgeFLopes
GeorgeFLopesAuthorAnswer
Visitor III
March 26, 2024

This worked for me, thx

 

curl --location "https://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member" --insecure -H "Authorization: Bearer **********" --header 'Content-Type: application/json' --request POST --data-raw '

{"name":"10.10.10.10"}

'

 

curl --location "https://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member/10.10.10.10" --insecure -H "Authorization: Bearer ****" --header 'Content-Type: application/json' --request DELETE

 

curl --location "hhttps://***.***.***.***/api/v2/cmdb/firewall/addrgrp/GROUPNAME/member/" --insecure -H "Authorization: Bearer ****" --header 'Content-Type: application/json' --request GET

Thought Leadership. Security Summit. Thursday, November 12th, PGA National Resort, Palm Beach Gardens, FL.
Thought Leadership. Security Summit. Thursday, October 8th. Disney's Grand Californian Hotel & SPA, Anaheim, CA.