Technical Tip: Python Script Example for FortiGate REST API
| Description | This article demonstrates how to access a FortiGate via REST API using a Python script. |
| Scope | FortiGate. |
| Solution | The REST API token needs to be obtained from the FortiGate. Below is the link that has instructions on how to obtain a REST API token: FortiGate 7.4.8 REST API administrator Guide
The script below is an example to retrieve system status, which is equivalent to 'get system status'.
import requests
url = "https://FGT IP/api/v2/monitor/system/status" payload = "" response = requests.request("GET", url, headers=headers, data=payload, verify=False) output = response.json() print(json.dumps(output, indent=4)) The URL can be changed to retrieve different information from the FortiGate. It is recommended to use the certificate by removing 'verify=False'.
Below are the results of the script.
{ |