Skip to main content
ToddS
New Member
July 1, 2025
Solved

FortiSwitch using FortiManager API

  • July 1, 2025
  • 2 replies
  • 1937 views

 

Hi all -

 

I have been fighting with the FortiManager API for a while now.  With a Python script, I've been able to:

  • Authenticate to Fortimanager
  • Query all Fortigates in FortiManage
    • Loop through the devices to find a specific Fortigate
  • Collect details from any individual or all Fortigates including
    • Interface Status, IP address, subnet, vlan and description
    • Grab the Switch Hostname, Serial Number and number of ports

I am struggling with figuring out how to pull the switch details for:

  • Mgmt IP address
  • Model Number (It appears to part of the start of the serial number)

I'm pretty sure I can get it pretty easy from the FortiOS directly, but I'm really hoping to pull the details from FortiManager with the same "connection".  I can see the details in FortiManager under FortiSwitches.

 

Any ideas anyone?

 

Thanks,

-Todd

 

Best answer by ToddS

I think I found the issue... The only thing that I changed was:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"                  # If we want to filter by a specific device, we can add scope         data = None         if device_name:             print(f"Filtering switches for device: {device_name}")             data = {                 "scope member": {                     "name": device_name                 }             }                  response = self._make_request(url_path, method="get", data=data, verbose=True)

 

"verbose=True"

2 replies

Richie_C
Staff
Staff
July 1, 2025

Hi Todd 

 

From the docs, it looks like you should be targetting:

 

/pm/config/adom/<ADOM_NAME>/obj/fsp/managed-switch

The table returns platform and vlan interface. 

 

Regards

 

ToddS
ToddSAuthor
New Member
July 1, 2025

Thanks for the reply Richie. 

 

I have been fighting with "/pm/config/device/{device}/vdom/{vdom}/switch-controller/managed-switch/{switch-id}"  thinking the data should be there, but never got the results I expected.

 

I thought the "/pm/config/adom/<ADOM_NAME>/obj/fsp/managed-switch" was for FortiOS as I was reading through the docs.  I do see that it is recognized by FortiManager.  I'm still working on the details... Currently trying:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"                  data = None         if device_name:             print(f"Filtering switches for device: {device_name}")             data = {                 "scope member": [                     {                         "name": device_name,                         "vdom": "root"                     }                 ]             } 

 

Output is not working... yet...

{'id': 1,  'result': [{'data': [],              'status': {'code': 0, 'message': 'OK'},              'url': '/pm/config/adom/{redacted adom}/obj/fsp/managed-switch'}]}

 

I'm not giving up yet. 

 

Thanks,

-Todd

ToddS
ToddSAuthorAnswer
New Member
July 1, 2025

I think I found the issue... The only thing that I changed was:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"                  # If we want to filter by a specific device, we can add scope         data = None         if device_name:             print(f"Filtering switches for device: {device_name}")             data = {                 "scope member": {                     "name": device_name                 }             }                  response = self._make_request(url_path, method="get", data=data, verbose=True)

 

"verbose=True"

filiaks1
Explorer III
July 1, 2025

The API preview option may help FortiManager 7.6 Features - Preview configuration changes in JSON API and CLI format | Fortinet Video Library also CLI scripts | FortiManager 7.6.3 | Fortinet Document Library are there is anything is not supported.

 

Outside of that Fortinet Developer Network is for API but for some reason Fortinet wants 2 employees to approve this so see with your sales/account.

ToddS
ToddSAuthor
New Member
July 1, 2025

Good idea.  Thanks @filiaks1 

 

-Todd