FortiGate
FortiGate Next Generation Firewall utilizes purpose-built security processors and threat intelligence security services from FortiGuard labs to deliver top-rated protection and high performance, including encrypted traffic.
lpizziniaco
Staff
Staff
Article Id 391650
Description Some FortiGate API endpoints return a limited number of results per request (typically up to 1000 entries). This article explains how to use pagination to retrieve the full dataset using multiple API calls.
Scope REST API, FortiGate.
Solution

This article describes how to use pagination for some FortiGate API calls to retrieve all the entries in the case the number of results exceeds the default limit for single response, using the entrypoint /api/v2/monitor/firewall/internet-service-details as an example.

 

When querying the FortiGate API endpoint, the number of returned entries items is limited to 1000 per request. A script querying the API with, (for example, GET /api/v2/monitor/firewall/internet-service-details?id=<service_id>) returns only the first 1000 entries, even if some Internet Services (e.g. Microsoft-Azure) contain a lot more (e.g. 44936).

The API limit enforces a maximum number of 1000 retrieved entries in a single call.

To retrieve all entries, it is first important to determine the total number of entries using the summary_only=1 parameter:

 

GET /api/v2/monitor/firewall/internet-service-details?id=<service_id>&summary_only=1


Once this parameter is retrieved, pagination must be implemented by iterating through results using the start parameter in steps of 1000. For example, in order to fetch all entries for id=327786 (Microsoft-Azure), the script must generate a series of requests like the following:

 

GET /api/v2/monitor/firewall/internet-service-details?id=327786&count=1000&start=0&vdom=root
GET /api/v2/monitor/firewall/internet-service-details?id=327786&count=1000&start=1000&vdom=root
GET /api/v2/monitor/firewall/internet-service-details?id=327786&count=1000&start=2000&vdom=root
...