API conventions: pagination, filters and errors¶
An API with hundreds of operations would be unmanageable if each one did things its own way. The Pandora FMS API does not: almost every list paginates, filters and sorts the same way, and every error has the same shape. Learning these rules once pays off across the whole reference.
This chapter assumes you already know how to identify yourself (Getting started and authentication). What follows is what you need to know to ask for data sensibly and to understand what the API tells you when something goes wrong. Everything stated here has been checked against a real console; the complete examples are in Usage examples.
Lists: GET and POST¶
Each entity with a list usually offers two routes with the same name:
| Route | What it is for |
|---|---|
GET /…/list |
Simple list. Pagination and sorting go in the address, as parameters (?page=0&sizePage=50). |
POST /…/list |
List with filters. The filters go in the JSON body. Pagination and sorting can also be passed as address parameters. |
The body of a POST …/list is the entity's own filter: every field you fill in is an exact-equality condition, and all of them are combined with AND. The available fields are those of the entity, and each page of the reference lists them in its request body table. A field that does not exist gives a 400 (Field: nope is not a valid parameter).
What a list returns¶
Paginated lists return an object with two parts: the data and the pagination information.
{
"paginationData": {
"totalPages": 3,
"sizePage": 50,
"currentPage": 0,
"totalRegisters": 120,
"totalRegistersPage": 50,
"unfilteredTotalRegisters": 120
},
"data": [ ]
}
paginationData field |
What it is |
|---|---|
totalPages |
Number of pages with the filter applied. |
sizePage |
Items per page. |
currentPage |
Current page, counting from 0. null if you use limit and offset. |
totalRegisters |
Items that match the filter. |
totalRegistersPage |
Items returned in this page. |
unfilteredTotalRegisters |
Items there would be without filtering. In some lists, such as events, it equals totalRegisters. |
limit, offset |
Only if you use that pagination mode; see below. |
The values in the example are illustrative. If you do not ask for pagination, totalPages is 0 and sizePage and currentPage are null.
Pagination¶
Pagination is controlled with page and sizePage:
| Parameter | Detail |
|---|---|
page |
Page number, starting at 0. If omitted, it is the first one. |
sizePage |
Items per page, at least 1. |
Without sizePage there is no limit
If you do not set sizePage, the list returns everything that matches the filter, in a single response, even if you set page. On a large console that can be a lot. Always ask for sizePage.
page and sizePage can be passed in the address or in the filter body of a POST …/list. Asking for a page that does not exist is not an error: it returns an empty data with a 200.
There is a second, offset-based mode, set in the body: limit (how many items; 0 returns none) and offset (how many to skip, 0 by default; without limit it returns all the rest). It is useful for walking through a set in arbitrary windows. The two modes cannot be mixed, not even if one goes in the body and the other in the address: it is a 400 (limit/offset cannot be combined with page/sizePage). A negative page or a sizePage lower than 1 also give a 400 (Field sizePage must be an integer greater than or equal to 1).
Sorting¶
| Parameter | Detail |
|---|---|
sortField |
Field to sort by. The valid values depend on the entity; an invalid value gives a 400 that lists the valid ones. |
sortDirection |
ASC or DESC, case-insensitive. |
If you do not set an order, each list uses its own (the agent list returns the newest first). If you need a stable order, set sortField.
Advanced filters¶
Besides the entity's fields, the body of a POST …/list almost always accepts these common options. Almost, because some lists have their own filters and do not accept them (events, for example: see Usage examples). The body table of each list in the reference says which ones it accepts:
| Option | What it does |
|---|---|
requestedFields |
List of fields you want to receive. If you do not ask for all of them, the server queries only those. Each name must be a valid field of the entity. The old fields option is still accepted. |
freeSearch |
Text searched in several fields at once, on the entities that support it. |
multipleSearch |
Several numeric values for one field: {"field": "…", "data": [1, 2, 3]}. |
multipleSearchString |
The same with text values. |
fieldConditions |
List of conditions with an operator, joined with AND: {"field": "…", "operator": "…", "value": …}. |
These options do not accept every field of the entity, only a subset: on agents, for example, interval works for the simple body filter but not for fieldConditions. If you use a field that is not valid, the 400 lists the valid ones; it is the quickest way to discover them.
The fieldConditions operators are case-insensitive, and almost all of them have an alias:
| Operator | Alias |
|---|---|
= |
eq |
!= |
ne |
<> |
(none) |
>, >= |
gt, gte |
<, <= |
lt, lte |
LIKE, NOT LIKE |
like, not_like |
REGEXP, NOT REGEXP |
regex, not_regex |
IN, NOT IN |
in, not_in (the value must be a list) |
BETWEEN, NOT BETWEEN |
between, not_between |
IS NULL, IS NOT NULL |
is_null, is_not_null |
IS EMPTY, IS NOT EMPTY |
is_empty, is_not_empty |
An operator that is not in the table gives a 400 (Operator … is not a valid filter operator); so does using IN or NOT IN without a list. One point is confusing: LIKE means "contains", not the SQL LIKE. The % is not a wildcard, it is searched as text: LIKE with web finds docs-test-web-01, and with docs-test-web% it finds nothing.
Consoles and nodes¶
On a standalone console you do not need to think about this. In an environment with Command Center, some resources belong to a specific node, and the serverId parameter says which one. Whether it is mandatory depends on the operation (for example, operations that modify federated resources require it, and some aggregated lists accept it as optional); the description of each serverId parameter in the reference says so.
Creating, changing and deleting¶
Write operations follow the same pattern in almost every entity:
| Operation | What it does | Response |
|---|---|---|
POST /entity |
Creates. | 200 with the created object and its identifier. Whatever you do not set takes its default value. |
PUT /entity/{id} |
Changes only the fields you send; the rest stays as it was. | 200 with the changed object. |
DELETE /entity/{id} |
Deletes. | 200 with the body null. If it no longer exists, 404. |
The reference only marks as required the fields that the swagger declares, and sometimes the server demands more (creating a user asks for four fields and the reference marks one). If one is missing, the 400 says which, such as Agent alias is missing.
Errors¶
Every error returns the same body, with the matching HTTP code:
{ "error": "message" }
| Code | When it happens | What to do |
|---|---|---|
400 |
The request is malformed: a body that is not JSON or not of the expected type, a parameter that is not an integer, wrong pagination bounds, an invalid filter operator. | Read the message: it says which field or parameter fails. |
401 |
There is no valid credential, or your address is not in the API access list. | Check the token and the Authorization header (chapter 13.1). |
403 |
The user is disabled or does not have permission for that operation. | Check the token's user and its permissions. |
404 |
The item you name does not exist. | Check the identifier. |
429 |
Too many attempts on /auth/*. It carries a Retry-After header. |
Wait that many seconds. |
500 |
Internal failure. The message is always Internal server error: the API does not leak internal details. |
Look at the console's web server error log, where the detail is kept. |
Failures of an external service that the operation needs (for example, sending an e-mail) return 502 or 503 with a message that does say what went wrong.
How to read the reference¶
The endpoint reference is organised by domains (agents, modules, alerts, events, policies…) and each operation is presented the same way:
| Part | What it contains |
|---|---|
| Index | Each page starts with a table of all its operations (method, route and summary), linked to their detail. |
| Heading | The method, with its own colour, and the route, for example GET /agent/{idAgent}. |
| Description | What it does and the conditions that matter. |
| Parameters | Name, where it goes (path, query), type, whether it is required and its description. |
| Request body | The JSON fields. Nested objects are shown with the full path (field.subfield) and lists with []. The fields you send are always open. Below it comes a JSON example, collapsed, generated from the schema with placeholder values: it shows the shape of the body, not something to copy as is. If several operations on the page use the same schema, its fields are described once in the Models section at the end and the operations point to it. |
| Response | The fields of the successful response, collapsed: they open on click. |
| Errors | The codes that operation can return; their meaning is the one in the table above. |
An empty Required column means the specification does not mark the field as required; the server may still demand it.
Real responses deviate from the table in three ways, checked on a real console:
- Enumeration values are returned in upper case (
LEARNING,NEW,WARNING) even though the reference shows them in lower case. Requests accept both forms. - Fields that are only sent (for example,
passwordwhen creating a user) appear in the response table but are not returned. - A field that the table does not mark as
nullablecan come back asnull(for example, the counters of a newly created agent). The reference is in English and is regenerated with every version of the API.