Technical Tip: How to upgrade FortiGate firmware using the REST API
Description | This article describes how to upgrade FortiGate firmware programmatically using the REST API, covering authentication options, firmware upload, and post-upgrade verification. |
Scope | FortiGate. |
Solution | The FortiGate REST API provides a monitor endpoint that accepts firmware uploads and triggers the upgrade and reboot sequence automatically. The steps below describe the full process, from authentication through to post-upgrade cleanup. Prerequisites: Before starting, confirm the following:
Choose an authentication method. The firmware upload endpoint requires token-based (Bearer) authentication. Cookie-based sessions established via /logincheck do not have JSON API access enabled by default and will return HTTP 403 on the upload endpoint.
Option A: Use a pre-configured REST API admin account. Go to System -> Administrators, create an administrator with type 'REST API Admin', assign the super_admin profile, and generate an API key. Include the key in every request using the Authorization header: Authorization: Bearer <api-key>. Option B: Generate a temporary API token via SSH CLI If only a standard admin username and password are available, a temporary API user can be created via SSH before the upgrade and removed afterward. Connect to the FortiGate via SSH and run the following:
Use this key as the Bearer token for the upload request. Remove the user after the upgrade is complete (see Step 5). Step 2: Upload the firmware. Send a multipart POST request to the firmware upgrade endpoint: POST https://<FortiGate IP>/api/v2/monitor/system/firmware/upgrade. The request must include the following:
The 'source' field is required. Omitting it returns HTTP 424. A successful response returns HTTP 200 or 202. The FortiGate immediately begins writing the firmware to the inactive flash partition and reboots. Wait for the device to come back online. After the upload is accepted, the FortiGate reboots into the new firmware. Reboot time is typically 3 to 8 minutes, depending on the hardware platform and configuration size.
Poll SSH or HTTPS at regular intervals (every 20 seconds is recommended) until a successful connection is established.
Verify the upgrade.
Alternatively, query the REST API: GET https://<FortiGate IP>/api/v2/monitor/system/status. Confirm that the 'version' field in the response matches the expected firmware version.
If a temporary API user was created in Step 1, remove it via SSH: |
