Skip to content

Getting started and authentication

Everything you do in the console with the mouse (create an agent, review an event, assign an alert) can also be done by a program. That is what the Pandora FMS API v2 is for: an HTTP interface that speaks JSON and that any script, integration or external tool can use without going through the screen.

Before you call anything, you have to answer a plain but decisive question: who is calling? The API does not serve strangers, and the two ways of introducing yourself (a user session or an API token) have different rules, different lifetimes and different uses. This chapter explains them. The everyday conventions (pagination, filters, errors) are in API conventions, and the endpoints, one by one, in the reference.

What you need

Requirement Detail
API address It hangs off the console, under api/v2. If the console is at https://pandora.example.com/pandora_console, the API is at https://pandora.example.com/pandora_console/api/v2.
User A console user. Requests run with that user's identity, so they only see and change what that user can see and change.
Allowed origin If the console restricts the API by IP address, yours must be on the list; otherwise the response is a 401 with the message IP <address> is not in ACL list.
Secure connection Use HTTPS. Credentials and tokens travel with every request.

The examples in this chapter use the PANDORA variable for the API address:

export PANDORA="https://pandora.example.com/pandora_console/api/v2"

How to talk to the API

  • Request bodies are sent as JSON, with the Content-Type: application/json header.
  • Responses are JSON.
  • Errors always have the same shape: {"error": "message"}, with the matching HTTP code. The table of codes is in API conventions.

Two ways to identify yourself

User session API token
Obtained with POST /auth/login (user and password) POST /token, with a session or with another token
Lifetime The access token lasts 30 minutes; the session is renewed while there is activity and ends after 7 days without use Whatever you set: without an end date, it does not expire
Two-factor authentication Solved at login Not involved: the token is already the credential
Used for A person or an application that signs in Scripts, integrations and unattended tasks

The practical rule: if someone is sitting there typing their password, use a session; if a machine runs it at three in the morning, use a token.

With a user session

Signing in

curl -s -c cookies.txt -X POST "$PANDORA/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"id_user": "admin", "password": "<password>"}'
Field Required Detail
id_user Yes User identifier.
password Yes Password.
isMobile No true if the session belongs to a mobile application.
deviceInfo No Device data (identifier, platform, application version, language, time zone).

The response carries what you need to continue:

Field What it is
status Login status: authenticated if all went well, or mfa_required if the second factor is needed (see below).
access_token The token you will send with every request.
access_expires_in Seconds of life of the access token: 1800.
session_expires_at Date on which the session ends if there is no activity.
id_user The user who has signed in.

The second half of the credential does not appear in the body: the server leaves the renewal token in a cookie named pandora_refresh, marked HttpOnly and SameSite=Strict (and Secure if you use HTTPS), valid for seven days. A command-line script does not see it unless it stores it; that is why the example uses -c cookies.txt.

Two-factor authentication

If the account has two-factor authentication, login does not return tokens: it returns status: mfa_required and a short-lived mfa_token (180 seconds). You complete it with the six-digit code:

curl -s -c cookies.txt -X POST "$PANDORA/auth/login/mfa" \
  -H "Content-Type: application/json" \
  -d '{"mfa_token": "<mfa_token>", "code": "<six-digit code>"}'

Five wrong codes invalidate the mfa_token, and you have to start again from login.

Using, renewing and closing the session

The access_token is sent in the Authorization header, as explained below. When it expires (after 30 minutes), you do not need to ask for the password again:

curl -s -b cookies.txt -c cookies.txt -X POST "$PANDORA/auth/refresh"

The response has the same shape as the login one. Renewal rotates the session: the previous access and renewal tokens stop working (the old access token gets a 401) and you receive a new pair. Without the cookie, renewal answers 401 with Session expired.

To close and revoke the session, use POST /auth/logout: it answers {"status": "logged_out"} and from then on neither the access token nor the renewal works.

Failed attempts are limited

/auth/login and /auth/refresh answer 429 with a Retry-After header (seconds to wait) when the limit is exceeded:

Rule Limit Block
Same address and same user 5 failures in 10 minutes 10 minutes
Same address, any user 20 failures in 10 minutes 10 minutes
Same user, any address 20 failures in 30 minutes 15 minutes
Renewals from the same address 60 in 1 minute 1 minute

A script that retries without looking at Retry-After only manages to lock itself out for longer. In tests, the sixth consecutive failed attempt by the same user from the same address received 429 with Retry-After: 600. A wrong password, before the limit, answers 401 with Invalid credentials.

With an API token

An API token is the credential for unattended processes: it does not depend on any cookie, there is no second factor to solve and it lasts as long as you decide.

It is created with POST /token. Since creating it requires being identified, the first token comes from a session: you sign in, use the access_token to create the token, and from then on the script no longer needs the password.

curl -s -X POST "$PANDORA/token" \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{"label": "nightly-backup"}'
Field Required Detail
label Yes Name to recognise it in the list.
validity No Date until which it is valid, in YYYY-MM-DD HH:MM:SS format (for example, 2027-01-01 00:00:00). Any other format gives a 400. Empty: it does not expire.
idUser No Owner. By default, the user who creates it.

The response includes the full token in the token field, in the form <identifier>-<secret>. This is the only time you will see it: the console does not store the secret as is, only a fingerprint to check it against. Keep it wherever you keep the rest of your credentials, never inside the script's code.

To manage them: GET /token/list lists them, PUT /token/{id} changes them and DELETE /token/{id} revokes them. In the list, the token field is always empty (the secret is never shown again) and you will also see, labelled API session, the credentials of your sessions, both access and renewal ones. A revoked token stops working on the next request, so revoking the token of a compromised script is immediate. Every use updates the last-use date, which appears in the list and helps you find dead tokens.

Sending the token

Both kinds of credential are presented the same way, in the Authorization header:

curl -s "$PANDORA/agent/list?page=0&sizePage=10" \
  -H "Authorization: Bearer <token>"

With a session, <token> is the access_token; with an API token, the value of the token field.

If it is missing, malformed or expired, the response is 401:

Response Cause
401, You need to be authenticated to perform this action The header is missing, the token does not exist, it has expired or the secret is wrong. The API deliberately does not tell these cases apart. It also happens if you send a renewal or second-factor token: only access tokens work outside /auth.
401, IP <address> is not in ACL list The source address is not in the console's list.
401, Invalid credentials Wrong user or password in /auth/login.
401, Session expired /auth/refresh without a renewal cookie, or with a session that is already closed or expired.
403, This user account has been disabled The token's user is disabled.

Pandora AI tokens

Pandora AI tokens are a special case: the console creates and manages them, and they cannot be created, modified or deleted through the API. If you call with one, every request must carry exactly one X-Pandora-AI-Session header with a session identifier (non-blank UTF-8 text, up to 255 characters, without control characters). If it is missing or invalid, the response is 400, even if the token is correct. The identifier is stored in the audit log for that request. Regular tokens ignore the header.

How this part is organised

Chapter Contents Languages
13.1 Getting started and authentication This chapter. Spanish, English and French
13.2 API conventions Pagination, filters and errors. Spanish, English and French
13.3 Usage examples Tested recipes: lists with filters, events, creation, changes and deletion. Spanish, English and French
13.4 Endpoint reference Every API operation: parameters, fields and errors. English only
13.5 CLI of the API v2 (pandora-cli) The terminal client: credentials, output, filters, API limits and recipes. Spanish, English and French
13.6 CLI command reference The 75 entities and their commands. English only

The reference is always in English

The endpoint reference is neither written by hand nor translated: a script generates it from the API specification, so it stays up to date with every version and is always in English, whatever the language of the documentation. The rest of this part is written and translated.

The spec of your console

Every console publishes the swagger of its own version at <console>/api/v2/swagger.json, without authentication, and an interactive Swagger UI at <console>/api/documentation/. The reference in this manual is that of the published version: if your console is a different version, the swagger of your console rules.