Devices API

Complete reference for the action=dispositivo area: reading the monitoring topology, CRUD of groups, devices and sensors, SNMP interface discovery and querying the sensor catalog.

Overview New in 7.2

The Devices API lets external provider systems (ERP, automation scripts, in-house dashboards, another Ravi server used as a remote dashboard source) query and manage the monitoring tree without opening the web interface. With it you can:

  • Read the full topology (groups, devices and sensors) with current status and values.
  • Create, edit and delete groups, devices and sensors.
  • Pause and resume sensors, for example to silence alerts during scheduled maintenance.
  • Run SNMP interface discovery through the API and create traffic sensors for the chosen ports.
  • Query the sensor catalog (categories and models) to know which model_id to use when creating.
  • Get a status summary (sensor count by state) to integrate into external dashboards.
  • Read a group in depth, a sensor in detail and a sensor's reading history.
  • Search the whole tree by name and query the alert history.

In 7.2 this area started using the same code core as the native Devices screen. A sensor created via the API is a real sensor: the SNMP query is validated on the spot, the alert conditions are evaluated and the interface reflects the change immediately. Also new in 7.2 are the operations edit_sensor, edit_device, edit_group, sensor_descobrir, sensor_categorias, sensor_modelos and delete_all_sensors. The reads get_group, get_sensor, get_sensor_history, alerts and search round out the area.

Prerequisites

  • API key with the Device Access permission checked (see Create an API key). Without the permission the call receives HTTP 403 with {"status":"error","message":"Access denied for dispositivo"}.
  • There is no plan requirement and no distinction between Master and Admin: the key grants access to the whole module.
  • For operations that query SNMP (add_sensor of SNMP models and sensor_descobrir), the device needs SNMP configured and reachable from the Ravi server.

When checking the permissions in the key modal, watch the checkbox position: in the current version the second item in the grid is the Devices one, even if the displayed label looks like the Concentrators one (the third item is the Concentrators one). The checkbox order is what counts.

Address and call format

All operations use the single API endpoint, with action=dispositivo and the operation in operation. Parameters can go via GET or POST (prefer POST in production so the token does not end up in URL logs).

format
GET/POST  https://YOUR-SERVER/api/api.php?token=KEY&action=dispositivo&operation=OPERATION_NAME&...

The response is always application/json; charset=utf-8. Gateway errors come with HTTP 400 (no token or action), 401 (invalid token) and 403 (no permission). Errors inside the module, however, usually return with HTTP 200 and the error in the body.

Response formats

The response body varies by operation; each reference card below shows the exact format. For error handling in your client, treat both cases: treat as an error any HTTP status greater than or equal to 400, a body with "msg" or a body with "status":"error".

FormatOperationsSuccessError
Direct object list_groups, list_devices, list_sensors, get_group, get_device, get_sensor, get_sensor_history, alerts, search, add_group, add_device, pause_sensor, resume_sensor, delete_sensor, delete_device, delete_group, status_summary, topology Body directly with the data, or {"msg":"ok", ...} on writes {"msg":"error text"} (HTTP 200)
status envelope add_sensor, sensor_categorias, sensor_modelos, sensor_descobrir, delete_all_sensors, edit_sensor, edit_device, edit_group {"status":"success", ...} {"status":"error","message":"..."}

A nonexistent or misspelled operation returns {"msg":"Invalid device operation"}.

Concepts

ConceptWhat it is
GroupNode of the monitoring tree. Groups can contain subgroups and devices. parent_id = 0 means root.
DeviceMonitored equipment (IP + brand). It belongs to a group (group_id) and has a brand code (equipment).
SensorA metric monitored within a device. Each sensor is born from a catalog model and has a numeric status (table below).
Sensor modelCatalog entry that defines what to collect. The catalog is organized into categories. To create a sensor via the API you must provide the model_id: find it with sensor_categorias and sensor_modelos.
Model protocols1 = SNMP (subtype 1 = simple query; subtype 2 = interface, requires discovery first), 2 = ping, 8 = aggregator (sum of other sensors). Other catalog protocols are not supported by creation via the API.
SNMP cascadeThe SNMP configuration used follows the same cascade as the screen: system default, overridden by the group's own SNMP (if active), overridden by the device's own SNMP (if active).
Sensor group (grupo_sensor_id)Visual grouping of sensors in the device panel. The API only assigns the sensor to an existing group; managing these groups is done through the interface.

Sensor status

The status and status_text fields in the listings use these codes:

Codestatus_textMeaning
1OfflineSensor with no response.
2PausedManually paused; not tested and does not alert.
3AlertAlert condition reached.
4CriticalCritical condition reached.
5Not testedNew or resumed sensor, awaiting the first collection cycle.
6OKNormal.
20SNMP failureThe equipment responded, but the SNMP query failed.

There are internal sub-states (7 to 14, variations of alert and critical). In the topology operation they already come collapsed into codes 3 and 4; in the other listings the raw code is returned.

Cross-cutting read endpoints

Beyond the operations organized by group, device and sensor, the area offers two reads that cut across the whole tree: the alert history and the global search. Both respond with the direct data object.

GET /api/api.php?action=dispositivo&operation=alerts

Lists the recorded alerts, newest first, with the source device and sensor, the notification channels fired and the duration of each occurrence.

ParameterTypeRequiredDescription
limitintno (default 100)Maximum number of alerts returned.
only_activeboolno (default false)"true" returns only alerts not yet resolved.
group_idintnoFilters the alerts by the devices of a group.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=alerts&only_active=true&limit=50"
response (abridged)
{"alerts":[{"id":9012,"date":"2026-07-04 09:15:00","sensor_id":8623,"sensor_name":"Tráfego sfp-sfpplus1",
  "device_id":5,"device_name":"RB Borda","device_ip":"10.0.0.1","type":3,"type_text":"Alert","tag":"ifMikrotik",
  "messages":["Traffic above the threshold"],
  "notifications":{"telegram":1,"email":1,"whatsapp":0,"push":0},
  "resolved":false,"resolved_date":null,
  "duration":{"days":0,"hours":1,"minutes":23,"seconds":11,"total_seconds":4991,"formatted":"01:23:11"}}],
 "total":1,"active_count":1}

The type field uses these codes, with the corresponding label in type_text; any other value comes back with type_text Unknown:

typetype_text
1Offline
2Paused
3Alert
4Critical
5Not tested
7Warning
10Critical
  • resolved tells whether the alert is already resolved; in that case resolved_date carries the date and duration is the total time. For active alerts, the duration is counted up to the query moment.
  • duration.formatted comes as HH:MM:SS, prefixed by the day count when there is one: for example "06:35:20" for less than a day and "2d 05:30:45" from one day on.
  • The four notifications fields (telegram, email, whatsapp, push) are numbers, not booleans: 0 = not sent, 1 = sent when the problem appeared, 2 = sent on the problem's resolution, 3 = send failure.
  • total is how many alerts came in the response; active_count, how many of them are still active.
GET /api/api.php?action=dispositivo&operation=search

Text search across the whole monitoring tree, returning the groups, devices and sensors that match the term. Useful for a search bar in an external dashboard. The term is compared as a substring (contains), case-insensitive: groups by name, devices by name or IP and sensors by name or tag.

ParameterTypeRequiredDescription
querystringyesSearch term (minimum 2 characters).
typestringno (default all)Restricts the type: all, groups, devices or sensors.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=search&query=borda&type=all"
response
{"results":{
  "groups":[{"id":12,"name":"POP Centro","parent_id":0}],
  "devices":[{"id":5,"name":"RB Borda","ip":"10.0.0.1","group_id":12,"equipment":"Mikrotik"}],
  "sensors":[{"id":8623,"name":"Tráfego sfp-sfpplus1","device_id":5,"device_name":"RB Borda",
              "status":6,"status_text":"OK","tag":"ifMikrotik"}]}}

With type other than all, only the matching list is filled; the others come empty. Each list returns at most 50 results per type: if any of them comes with 50 items, refine the search term. In the devices, equipment comes as the brand name (unlike list_devices, which returns the numeric code). Error: Search query must be at least 2 characters.


Groups

Operations on the nodes of the monitoring tree: list by level, create, edit (including own SNMP, map position and automations) and delete.

GET /api/api.php?action=dispositivo&operation=list_groups

Lists the groups of one level of the tree. It is not recursive: it returns only the requested level, in the order they appear on the screen.

ParameterTypeRequiredDescription
parent_idintno (default 0)Parent group ID. 0 lists the root groups.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_groups&parent_id=0"
response
{"groups":[{"id":12,"name":"POP Centro","parent_id":0},{"id":15,"name":"Backbone","parent_id":0}]}
GET /api/api.php?action=dispositivo&operation=get_group New in 7.2

Returns a group with its full subtree and a status summary. Unlike list_groups (which returns a single level), this operation descends recursively through the subgroups and, by default, includes the devices and sensors of each level.

ParameterTypeRequiredDescription
group_idintyesRoot group of the query.
include_devicesboolno (default true)"false" omits the device list of each group (returns only the group structure).
include_sensorsboolno (default true)"false" omits the sensors of each device.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=get_group&group_id=12"
response (abridged)
{"group":{"id":12,"name":"POP Centro","parent_id":0,
  "subgroups":[{"id":18,"name":"Sala técnica","parent_id":12,"subgroups":[],"devices":[],"stats":{}}],
  "devices":[{"id":5,"name":"RB Borda","ip":"10.0.0.1","group_id":12,"equipment":"Mikrotik",
    "sensors":[{"id":301,"name":"Carga de CPU","device_id":5,"status":6,"status_text":"OK",
                "value":"12%","tag":"cpuMikrotik","unit":"%","schedule":"1m"}],
    "status":{"total_sensors":1,"sensors_ok":1,"sensors_alert":0,"sensors_error":0,
              "sensors_offline":0,"sensors_paused":0,"overall":"ok"}}],
  "stats":{"total_devices":8,"total_sensors":64,"sensors_ok":60,"sensors_alert":1,
           "sensors_error":0,"sensors_offline":2,"sensors_paused":1}}}
  • Each subgroups node repeats the same structure (subgroups, devices, stats), recursively.
  • In the devices, equipment comes as the brand name (for example "Mikrotik", "Outro"). list_devices and get_device, on the other hand, return the brand's numeric code (add_device table).
  • Each sensor carries id, name, device_id, status, status_text, value (formatted), tag, unit and schedule. The unit and schedule fields appear only here: list_sensors does not return those two.
  • Each device also carries a status block summarizing the equipment (fields in the table below).
  • The stats block counts the subtree's sensors by state (sensors_ok, sensors_alert, sensors_error, sensors_offline, sensors_paused), handy for a per-POP summary.

status block of each device

FieldContent
total_sensorsTotal sensors of the device.
sensors_okSensors OK.
sensors_alertSensors in alert (statuses 3 and 7).
sensors_errorSensors in error (statuses 4 and 20).
sensors_offlineOffline sensors (status 1).
sensors_pausedPaused sensors (status 2).
overallDevice summary, with precedence: error if there is a sensor in error, else alert, else offline, else ok. When no sensor fits (for example all not tested), it comes as unknown.

Errors: Group ID is required, Group not found.

POST /api/api.php?action=dispositivo&operation=add_group

Creates a group. The new group goes to the end of the level's order. A duplicate name at the same level is blocked (at different levels it can repeat).

ParameterTypeRequiredDescription
namestringyesGroup name. HTML characters are converted to entities.
parent_idintno (default 0)Parent group. 0 creates at the root.
curl
curl -s -d "token=KEY&action=dispositivo&operation=add_group&name=POP Norte" https://ravi.example.com/api/api.php
response
{"msg":"ok","group_id":77}

Errors: Group name is required, Group already exists at this level.

POST /api/api.php?action=dispositivo&operation=edit_group New in 7.2

Edits an existing group with PATCH semantics: it only changes what is sent; omitted fields stay as they are.

ParameterTypeRequiredDescription
group_idintyesGroup to edit.
namestringnoNew name.
parent_idintnoMoves the group to another parent.
ativasnmpintno2 = the group now has its own SNMP (inherited by the child devices that inherit); any other value = uses the system default.
snmp_versionintnoGroup SNMP version: 1, 2 or 3.
snmp_communitystringnoCommunity (v1/v2c) or user (v3).
snmp_portintnoSNMP port.
snmp_seclevel / snmp_authproto / snmp_cryptoproto / snmp_authpass / snmp_cryptopassstringnoSNMPv3 parameters: security level, authentication protocol, encryption protocol and the two passwords.
latitude / longitudedecimalnoMap position. Empty or non-numeric values are stored as null.
autosensorstringnoThe group's auto-sensor template (same value used by the screen; automatic sensor creation on the group's devices).
autoscanintnoTurns the group's Auto-discovery (network scan) on or off.
curl
curl -s -d "token=KEY&action=dispositivo&operation=edit_group&group_id=77&name=POP Norte 2&ativasnmp=2&snmp_version=2&snmp_community=publica&snmp_port=161" https://ravi.example.com/api/api.php
response
{"status":"success","group":{"id":77,"nome":"POP Norte 2","idGrupoPai":0}}

Errors: group_id is required, Group not found.

DELETE /api/api.php?action=dispositivo&operation=delete_group

Deletes a group. It only works on an empty group: no subgroups and no devices. Empty it first, moving the content with edit_device and edit_group.

ParameterTypeRequiredDescription
group_idintyesGroup to delete.
curl
curl -s -d "token=KEY&action=dispositivo&operation=delete_group&group_id=77" https://ravi.example.com/api/api.php
response
{"msg":"ok"}

Errors: Group ID is required, Group not found, Cannot delete group with subgroups, Cannot delete group with devices.


Devices

Operations on the monitored equipment: listing, detailed query, creation, editing (including own SNMP and SSH), deletion, status summary and the full topology in a single call.

GET /api/api.php?action=dispositivo&operation=list_devices

Lists the devices of a group. It is not recursive.

ParameterTypeRequiredDescription
group_idintno (default 0)Owner group. 0 lists the loose devices at the root.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_devices&group_id=12"
response
{"devices":[{"id":5,"name":"RB Borda","ip":"10.0.0.1","group_id":12,"equipment":2}]}
GET /api/api.php?action=dispositivo&operation=get_device

Returns a device with all its sensors (same sensor format as list_sensors).

ParameterTypeRequiredDescription
device_idintyesDevice to query.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=get_device&device_id=5"
response
{"device":{"id":5,"name":"RB Borda","ip":"10.0.0.1","group_id":12,"equipment":2,
  "sensors":[{"id":301,"name":"Carga de CPU","device_id":5,"status":6,"status_text":"OK","value":"12%","tag":"cpuMikrotik"}]}}

Errors: Device ID is required, Device not found.

GET /api/api.php?action=dispositivo&operation=status_summary

Status counters for external dashboards: total devices, total sensors and sensors by state.

ParameterTypeRequiredDescription
group_idintnoIf sent, considers only the devices directly inside that group (does not descend into subgroups). Without it, the whole system.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=status_summary"
response
{"total_devices":42,"total_sensors":310,
 "status_counts":{"offline":2,"paused":5,"alert":1,"critical":0,"untested":3,"ok":299}}

Note: the internal sub-states (7 to 14 and 20) do not go into the 6 counters, so the sum can end up slightly below total_sensors in scenarios with SNMP failure.

GET /api/api.php?action=dispositivo&operation=topology

Returns the full tree in a single call: groups with devices and sensors, root devices and also the lists of active OLTs, concentrators, DNS and Flow exporters. It is the operation used by the Dashboards environment for remote sources. It takes no parameters.

curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=topology"
response (abridged)
{"topology":{
  "groups":[{"id":12,"name":"POP Centro","parent_id":0,
    "devices":[{"id":5,"name":"RB Borda","group_id":12,
      "sensors":[{"id":301,"name":"Carga de CPU","status":6}]}]}],
  "devices":[],
  "olts":[{"id":1,"name":"OLT Central","ip":"10.0.0.9","status":1}],
  "concentradoras":[{"id":1,"name":"BNG-01","ip":"10.0.0.8","status":1}],
  "dns":[{"id":1,"name":"DNS Recursivo","primario":"10.0.0.53","secundario":"10.0.0.54"}],
  "flow":[{"id":0,"name":"Visão geral","ip":""},{"id":3,"name":"NE8000","ip":"10.0.0.7"}]
}}
  • The groups come flattened, all with parent_id; the client builds the hierarchy.
  • The sensor status already comes collapsed into codes 1 to 6.
  • Only active OLTs, active concentrators and active Flow exporters appear. The Flow item with id=0 is synthetic and represents the overview of all exporters.
  • On large bases the response is bulky: cache on the client instead of calling in a tight loop.
POST /api/api.php?action=dispositivo&operation=add_device

Creates a device. It is born without sensors: create them next with add_sensor or turn on the device or group auto-sensor.

ParameterTypeRequiredDescription
namestringyesDevice name.
ipstringyesValid IP (IPv4 or IPv6).
group_idintno (default 0)Owner group. 0 creates at the root.
equipmentintno (default 100)Brand code (table below).
curl
curl -s -d "token=KEY&action=dispositivo&operation=add_device&name=RB Borda&ip=10.0.0.1&group_id=77&equipment=2" https://ravi.example.com/api/api.php
response
{"msg":"ok","device_id":123}

Errors: Device name and IP are required, Invalid IP address, Device with this name or IP already exists. The duplicate check is global: the same name or the same IP in any group blocks creation.

Brand codes (equipment)

Same codes as the device screen. The brand matters: automatic sensor discovery and catalog model filtering are driven by it.

CodeBrandCodeBrand
1Ubiquiti12Cambium Networks
2Mikrotik13Ceragon
3Cisco14VOLT
4Juniper15XPS
5Huawei16ALGcom
6Fiberhome17Rondotec
7ZTE18Linux
8Intelbras19DATACOM
9PARKS20JFA
10v-Solution21a10
11Mimosa100Other
POST /api/api.php?action=dispositivo&operation=edit_device New in 7.2

Edits a device with PATCH semantics: only what is sent changes. After saving, the system reprocesses the device's auto-sensors in the background and regenerates the server's SNMP protection, the same effects as saving from the screen.

ParameterTypeRequiredDescription
device_idintyesDevice to edit.
namestringnoNew name.
ipstringnoNew IP (validated; invalid returns Invalid IP address).
group_idintnoMoves the device to another group.
equipmentintnoChanges the brand (codes from add_device).
herdar_snmpintno2 = the device uses its own SNMP (the snmp_* fields below); any other value = inherits from the group or the system.
snmp_versionintno1, 2 or 3.
snmp_communitystringnoCommunity (v1/v2c) or user (v3).
snmp_portintnoSNMP port.
snmp_seclevel / snmp_authproto / snmp_cryptoproto / snmp_authpass / snmp_cryptopassstringnoSNMPv3 credentials.
herdar_sshintnoAnalogous to SNMP, for the device's own SSH credentials.
ssh_user / ssh_pass / ssh_portstringnoDevice SSH credentials (used in the per-device terminal, backups, etc.).
limit_snmpgetintnoLimit of OIDs per SNMP query, for equipment that does not accept large queries.
infstringnoInformation field (free-form notes).
inf_sigilosasstringnoConfidential notes field (visible according to the screen permission).
auto_sensorintno0 turns off automatic sensor creation for this device; 1 or 2 turns it on.
curl
curl -s -d "token=KEY&action=dispositivo&operation=edit_device&device_id=123&herdar_snmp=2&snmp_version=2&snmp_community=noc&snmp_port=161" https://ravi.example.com/api/api.php
response
{"status":"success","device":{"id":123,"nome":"RB Borda","ip":"10.0.0.1","idGrupoPai":12}}

Errors: device_id is required, Device not found, Invalid IP address.

DELETE /api/api.php?action=dispositivo&operation=delete_device

Deletes the device and all its sensors.

The deletion is irreversible. This operation removes the sensor rows, but does not do the full cleanup of histories and auxiliary files: to fully wipe a device, run delete_all_sensors before deleting it.

ParameterTypeRequiredDescription
device_idintyesDevice to delete.
curl
curl -s -d "token=KEY&action=dispositivo&operation=delete_device&device_id=123" https://ravi.example.com/api/api.php
response
{"msg":"ok"}

Errors: Device ID is required, Device not found.


Sensors

Operations on the monitored metrics: list, create (with real SNMP validation), edit, pause, resume and delete (individually or in bulk).

GET /api/api.php?action=dispositivo&operation=list_sensors

Lists a device's sensors. The value field already comes formatted as on the screen (number + catalog unit, for example "87.5 mbps"); for paused, offline or new sensors it carries the state text (Paused, Offline, Sensor not tested).

ParameterTypeRequiredDescription
device_idintyesOwner device.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_sensors&device_id=5"
response
{"sensors":[{"id":301,"name":"Carga de CPU","device_id":5,"status":6,"status_text":"OK","value":"12%","tag":"cpuMikrotik"}]}

Error: Device ID is required.

GET /api/api.php?action=dispositivo&operation=get_sensor New in 7.2

Details a sensor: identification, status, current values (raw and averages per collector), unit, schedule, the source catalog model and, when there is an active alert condition, the context field with the conditions that fired. It is the most complete read of an individual sensor.

ParameterTypeRequiredDescription
sensor_idintyesSensor to query.
curl
curl "https://YOUR-SERVER/api/api.php?action=dispositivo&operation=get_sensor&sensor_id=8623&token=YOUR_TOKEN"
response (abridged)
{"sensor":{"id":8623,"name":"Tráfego sfp-sfpplus1","device_id":5,"device_name":"RB Borda",
  "device_ip":"10.0.0.1","status":6,"status_text":"OK","tag":"ifMikrotik","unit":"mbps",
  "schedule":"1m","error_count":0,
  "values":[{"name":"Download","raw_value":"87500000","extension":"mbps","average":"84.2"},
            {"name":"Upload","raw_value":"12300000","extension":"mbps","average":"11.8"}],
  "raw_values":{"value1":"87500000","value2":"12300000","value3":"","value4":""},
  "averages":{"avg1":"84.2","avg2":"11.8","avg3":"","avg4":""},
  "model":{"id":45,"name":"Interface traffic","protocol":1,"type":2}}}
  • values carries one item per active collector, each with name, raw_value, extension (unit) and average; raw_values and averages expose the four raw fields (value1..4 and avg1..4).
  • status follows the status table in the Overview; status_text is the label in the system language.
  • model identifies the source catalog model.
  • The context field only appears when the sensor has an active alert condition: it is the list of the conditions that fired, each item with the problem description (descricao field) and the condition data. A normal sensor (no active message) comes without the context field.

Errors: Sensor ID is required, Sensor not found.

GET /api/api.php?action=dispositivo&operation=get_sensor_history New in 7.2

Returns a sensor's reading history over a date range, with optional statistics per collector. Meant for external charts and reports.

ParameterTypeRequiredDescription
sensor_idintyesSensor to query.
start_datedateno (default today)Start date in YYYY-MM-DD format.
end_datedateno (default today)End date in YYYY-MM-DD format.
include_statsboolno (default true)"false" omits the statistics block.
limitintno (default 0)Maximum records returned in data. 0 = no limit.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=get_sensor_history&sensor_id=8623&start_date=2026-07-01&end_date=2026-07-04"
response (abridged)
{"sensor_id":8623,"sensor_name":"Tráfego sfp-sfpplus1","sensor_tag":"ifMikrotik",
 "start_date":"2026-07-01","end_date":"2026-07-04",
 "data":[{"timestamp":"2026-07-01 00:01:00","status":6,"status_text":"OK",
          "values":[{"name":"Download","value":"84.2","unit":"mbps"},
                    {"name":"Upload","value":"11.8","unit":"mbps"}]}],
 "total_records":5760,"returned_records":5760,
 "statistics":{"total_records":5760,"status_summary":{"6":5740,"3":20},
   "values_stats":{"Download":{"min":"0.4","max":"120.7","average":"84.2","unit":"mbps",
     "count":5760,"min_date":"2026-07-02 04:12:00","max_date":"2026-07-03 21:33:00"}}}}
  • Each data item carries the timestamp, the reading's status/status_text and the values per collector (name, value and unit).
  • total_records is how much exists in the range; returned_records is how much came after applying limit.
  • In statistics.values_stats, each key is one of the sensor's collectors, with minimum, maximum, average, unit, count and the dates of the minimum and maximum. status_summary counts the records by status code.

The history comes from the daily readings stored on the server. Older periods may be compacted; the endpoint reads both formats transparently, so long ranges may take more time to respond.

Errors: Sensor ID is required, Invalid date format. Use YYYY-MM-DD.

POST /api/api.php?action=dispositivo&operation=add_sensor New in 7.2

Creates one or more sensors from a catalog model. Reworked in 7.2: creation is real, with an SNMP query validated on the spot. The extra parameters depend on the model's protocol (find it with sensor_modelos).

ParameterTypeRequiredDescription
device_idintyesOwner device.
model_idintyesCatalog model (accepts the alias idSensor).
grupo_sensor_idintnoSensor group (tab) where the sensor goes in the device panel.
alvosJSON arrayping onlySeveral targets at once: [{"ip":"8.8.8.8","nome":"Google"}].
ping_ip / ping_nomestringping only (alternative)A single target. With no target at all, the ping is created against the device's own IP. An empty name uses the model name.
nomestringaggregator onlyAggregator sensor name.
idsCSV stringaggregator onlyIDs of the source sensors (minimum 2, all of the same type).
itensJSON arrayinterface onlyItems coming from sensor_descobrir: [{"index":"7","nome":"sfp-sfpplus1","valor1":"..."}].

What happens by model type:

  • Simple SNMP (protocol 1, type 1): the API makes a real SNMP query on the model's OIDs using the SNMP cascade. If any OID fails, the sensor is not created. The alert conditions are evaluated on the spot: the sensor is born with status 6 (OK) or 3 (Alert).
  • Interface (protocol 1, type 2): requires itens (flow: sensor_descobrir, choose, add_sensor). Creates one sensor per item, with initial status 5 (Not tested). Without itens, it fails with "Nenhuma interface informada (use sensor_descobrir)".
  • Ping (protocol 2): creates with status 5 and default ping parameters. Deduplication by IP: if a ping already exists for that IP on the device, the item counts as duplicate.
  • Aggregator (protocol 8): sums the values of the source sensors. Deduplication by set of IDs and by name. Possible failures: "Selecione ao menos 2 sensores", "Sensores de tipos diferentes", "Sensores nao encontrados".
curl
curl -s -d 'token=KEY&action=dispositivo&operation=add_sensor&device_id=123&model_id=45&itens=[{"index":"7","nome":"sfp-sfpplus1"}]' https://ravi.example.com/api/api.php
response
{"status":"success","message":"criados=3 duplicados=1 falhas=0",
 "criados":[{"id":501,"nome":"sfp-sfpplus1","statusAlert":"5","idDispositivo":123}],
 "duplicados":[{"error":"Ja existe um ping para este IP"}],
 "falhas":[]}

The response always carries the three sets criados, duplicados and falhas; status is success if at least one sensor was created. Typical failures inside falhas: SNMP nao configurado, Falha na consulta SNMP, OID messages (with the problematic OID in the oid field), Modelo sem coletores, Protocolo nao suportado: N. Direct errors: device_id and model_id are required, Device not found.

POST /api/api.php?action=dispositivo&operation=edit_sensor New in 7.2

Edits sensor properties with PATCH semantics, with one important exception for ping sensors (see the warning below).

ParameterTypeRequiredDescription
sensor_idintyesSensor to edit.
nomestringnoNew name (cannot be empty if sent).
valorstringnoThe sensor's "valor" field (interface index, ping IP, etc.). Be careful when changing it.
cronogramastringnoCollection interval: 30s, 1m (recommended default), 5m, 15m, 1h, 1d, 7d.
falhasstringno(Non-ping sensors) failure threshold before alarming.
ping_tamanhointsee warning(Ping only) packet size in bytes. Default 32.
ping_quantidadeintsee warning(Ping only) number of packets. Default 20.
ping_delayintsee warning(Ping only) interval between packets. Default 1.
ping_falhasintsee warning(Ping only) tolerated failures. Default 2.
display_tipointno1 = show 1 value; 2 = show 2 values (for example down/up).
display_separadorstringnoSeparator between the 2 values (maximum 4 characters, default " / ").
display_valor1 / display_valor2intnoWhich collector (1 to 4) appears in each position.

Ping sensors: when editing anything on a ping sensor, the four ping_* parameters that are not resent revert to the defaults (32/20/1/2). Always resend ping_tamanho, ping_quantidade, ping_delay and ping_falhas together when editing a ping sensor.

curl
curl -s -d "token=KEY&action=dispositivo&operation=edit_sensor&sensor_id=501&nome=Uplink SFP+1&cronograma=1m" https://ravi.example.com/api/api.php
response
{"status":"success"}

Errors: sensor_id is required, Sensor not found, nome obrigatorio.

POST /api/api.php?action=dispositivo&operation=pause_sensor

Pauses a sensor (status 2). A paused sensor is not collected and does not raise alerts. Useful for silencing by script during maintenance.

ParameterTypeRequiredDescription
sensor_idintyesSensor to pause.
curl
curl -s -d "token=KEY&action=dispositivo&operation=pause_sensor&sensor_id=501" https://ravi.example.com/api/api.php
response
{"msg":"ok"}

Errors: Sensor ID is required, Sensor not found.

POST /api/api.php?action=dispositivo&operation=resume_sensor

Resumes a paused sensor: it goes back to status 5 (Not tested) and takes on its real status in the next collection cycle.

ParameterTypeRequiredDescription
sensor_idintyesSensor to resume.
curl
curl -s -d "token=KEY&action=dispositivo&operation=resume_sensor&sensor_id=501" https://ravi.example.com/api/api.php
response
{"msg":"ok"}

Errors: Sensor ID is required, Sensor not found.

DELETE /api/api.php?action=dispositivo&operation=delete_sensor

Deletes a sensor. This simple operation does not clean histories and auxiliary files; for the full cleanup of a device use delete_all_sensors.

ParameterTypeRequiredDescription
sensor_idintyesSensor to delete.
curl
curl -s -d "token=KEY&action=dispositivo&operation=delete_sensor&sensor_id=501" https://ravi.example.com/api/api.php
response
{"msg":"ok"}

Errors: Sensor ID is required, Sensor not found.

DELETE /api/api.php?action=dispositivo&operation=delete_all_sensors New in 7.2

Deletes all of a device's sensors in a single call, mirroring the equivalent button on the screen: it removes the sensors, the associated history and alert records and the on-disk data caches. The cleanup is tolerant of partial failures in the histories.

Irreversible operation: the collection histories of the deleted sensors are erased along with them and cannot be recovered.

ParameterTypeRequiredDescription
device_idintyesDevice whose sensors will all be deleted.
curl
curl -s -d "token=KEY&action=dispositivo&operation=delete_all_sensors&device_id=123" https://ravi.example.com/api/api.php
response
{"status":"success","excluidos":14,"message":"14 sensor(es) excluído(s)"}

A device with no sensors returns excluidos: 0 still with success. Errors: device_id is required, Device not found.


Discovery and catalog New in 7.2

These three operations support sensor creation. The recommended flow is always: sensor_categorias to find the category, sensor_modelos to find the model_id and the protocol, sensor_descobrir if the model is an interface one and, finally, add_sensor. Do not use a "guessed" model_id.

GET /api/api.php?action=dispositivo&operation=sensor_categorias

Lists the categories of the sensor catalog (including the brand groups), already in the system language.

ParameterTypeRequiredDescription
device_idintnoIf sent, also returns the device's IP (useful to pre-fill the ping target).
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=sensor_categorias&device_id=123"
response
{"status":"success","lang":1,"cats":[{"id":4,"nome":"Mikrotik"},{"id":9,"nome":"Ping"}],"hostIp":"10.0.0.1"}

lang indicates the system language (1 = Portuguese, 2 = English, 3 = Spanish); the category names already come in that language.

GET /api/api.php?action=dispositivo&operation=sensor_modelos

Lists the catalog models by category and/or search term. The fields that matter for creating a sensor are the id (which becomes the model_id) and the protocolo/tipo pair, which defines which parameters add_sensor requires.

ParameterTypeRequiredDescription
group_idintnoID of the category (coming from sensor_categorias). Note: here group_id is a catalog category, not a tree group.
termstringnoSearch by name, description or tag (in the 3 languages). Without a category and with term, the search is global and limited to 80 results.
curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=sensor_modelos&group_id=4&term=trafego"
response (abridged)
{"status":"success","models":[{"id":45,"nome_pt":"Tráfego de interface","tag":"ifMikrotik","protocolo":1,"tipo":2}]}
POST /api/api.php?action=dispositivo&operation=sensor_descobrir

SNMP interface discovery for interface models (protocol 1, type 2, such as port traffic). It runs a synchronous SNMP walk on the equipment and returns the interfaces found, ready to be passed to add_sensor in the itens parameter.

ParameterTypeRequiredDescription
device_idintyesTarget device.
model_idintyesInterface model from the catalog.
timeoutintno (default 60)Seconds (minimum 5, maximum 240). If it overflows, it returns what it collected with truncado: true.
curl
curl -s -d "token=KEY&action=dispositivo&operation=sensor_descobrir&device_id=123&model_id=45&timeout=120" https://ravi.example.com/api/api.php
response
{"status":"success","itens":[{"index":"7","nome":"sfp-sfpplus1","valor1":"..."}],"total":48,"truncado":false}
  • The index can be composite (for example "idx|id2") in models that use two indexes: pass the value exactly as it came.
  • The HTTP call stays open until the walk finishes (up to 240 seconds). Set your HTTP client's timeout to a value greater than the requested timeout.

Errors: device_id and model_id are required, Device not found, Sem retorno da descoberta (timeout ou SNMP) (equipment did not respond within the deadline, wrong SNMP or model with no data).


Practical examples

Provision a complete POP: group, device and interface sensors

The example creates a group, registers a Mikrotik in it, discovers the interfaces via SNMP and creates the traffic sensors.

# 1) Create the group
curl -s -d "token=KEY&action=dispositivo&operation=add_group&name=POP Norte" \
  https://ravi.example.com/api/api.php
# -> {"msg":"ok","group_id":77}

# 2) Create the device (equipment=2 is Mikrotik)
curl -s -d "token=KEY&action=dispositivo&operation=add_device&name=RB Borda&ip=10.0.0.1&group_id=77&equipment=2" \
  https://ravi.example.com/api/api.php
# -> {"msg":"ok","device_id":123}

# 3) Discover the interfaces of model 45
curl -s -d "token=KEY&action=dispositivo&operation=sensor_descobrir&device_id=123&model_id=45&timeout=120" \
  https://ravi.example.com/api/api.php

# 4) Create the sensors for the chosen interfaces
curl -s -d 'token=KEY&action=dispositivo&operation=add_sensor&device_id=123&model_id=45&itens=[{"index":"7","nome":"sfp-sfpplus1"}]' \
  https://ravi.example.com/api/api.php
<?php
$base  = 'https://ravi.example.com/api/api.php';
$token = 'KEY';

function ravi($base, $params) {
    $ch = curl_init($base);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 300); // greater than the discovery timeout
    $out = json_decode(curl_exec($ch), true);
    curl_close($ch);
    // error in both formats: "msg" != ok or status=error
    if (isset($out['msg']) && $out['msg'] !== 'ok') throw new Exception($out['msg']);
    if (($out['status'] ?? '') === 'error') throw new Exception($out['message']);
    return $out;
}

$grupo = ravi($base, ['token'=>$token, 'action'=>'dispositivo',
    'operation'=>'add_group', 'name'=>'POP Norte']);

$disp = ravi($base, ['token'=>$token, 'action'=>'dispositivo',
    'operation'=>'add_device', 'name'=>'RB Borda',
    'ip'=>'10.0.0.1', 'group_id'=>$grupo['group_id'], 'equipment'=>2]);

$desc = ravi($base, ['token'=>$token, 'action'=>'dispositivo',
    'operation'=>'sensor_descobrir', 'device_id'=>$disp['device_id'],
    'model_id'=>45, 'timeout'=>120]);

ravi($base, ['token'=>$token, 'action'=>'dispositivo',
    'operation'=>'add_sensor', 'device_id'=>$disp['device_id'],
    'model_id'=>45, 'itens'=>json_encode($desc['itens'])]);
import requests, json

BASE  = "https://ravi.example.com/api/api.php"
TOKEN = "KEY"

def ravi(**params):
    params.update(token=TOKEN, action="dispositivo")
    r = requests.post(BASE, data=params, timeout=300)  # > discovery timeout
    out = r.json()
    # error in both formats: "msg" != ok or status=error
    if out.get("msg") not in (None, "ok") or out.get("status") == "error":
        raise RuntimeError(out.get("msg") or out.get("message"))
    return out

grupo = ravi(operation="add_group", name="POP Norte")
disp  = ravi(operation="add_device", name="RB Borda",
             ip="10.0.0.1", group_id=grupo["group_id"], equipment=2)
desc  = ravi(operation="sensor_descobrir", device_id=disp["device_id"],
             model_id=45, timeout=120)
ravi(operation="add_sensor", device_id=disp["device_id"],
     model_id=45, itens=json.dumps(desc["itens"]))

Maintenance window: pause and resume sensors by script

curl
# Before the maintenance: pause (repeat for each sensor from list_sensors)
curl -s -d "token=KEY&action=dispositivo&operation=pause_sensor&sensor_id=501" https://ravi.example.com/api/api.php

# After the maintenance: resume (comes back as "Not tested" until the next cycle)
curl -s -d "token=KEY&action=dispositivo&operation=resume_sensor&sensor_id=501" https://ravi.example.com/api/api.php

Ping against an external target

Find a ping model (protocol 2) with sensor_modelos and create the sensor pointing to the desired IP. Without ping_ip, the ping is created against the device's own IP.

curl
curl -s -d "token=KEY&action=dispositivo&operation=add_sensor&device_id=123&model_id=12&ping_ip=8.8.8.8&ping_nome=Google" \
  https://ravi.example.com/api/api.php

External dashboard with the status summary

curl
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=status_summary"
# -> {"total_devices":42,"total_sensors":310,"status_counts":{"offline":2,"paused":5,"alert":1,"critical":0,"untested":3,"ok":299}}

Best practices: one key per integration, POST + HTTPS in production, client-side cache for topology, and always delete_all_sensors before deleting a device you want to fully wipe. Edits are PATCH, so send only what changes, with the exception of the four ping_* parameters of edit_sensor.


Troubleshooting

Common symptoms in integrations with the Devices area and their likely causes.

SymptomLikely cause and solution
Invalid token (401) Wrong or revoked key. Remember that the on-screen display is masked after 2 hours, but the key stays valid; check that you copied the right key. See also the notes on editing keys in Create an API key.
Access denied for dispositivo (403) Key without the Devices permission checked. Adjust the key in Settings, Integrations tab.
{"msg":"Invalid device operation"} operation misspelled, or an attempt to use an operation that does not exist in this version. For reads use topology, get_device and the list_* operations.
add_sensor returns falhas with "SNMP nao configurado" No community, port or version was resolved by the cascade (system, group, device). Configure the system default SNMP or the device's snmp_* fields with herdar_snmp=2.
add_sensor returns "Falha na consulta SNMP" or an OID error Unreachable equipment, wrong community, blocked port, or the catalog model does not apply to that hardware (the problematic OID comes back in the oid field).
sensor_descobrir returns "Sem retorno da descoberta (timeout ou SNMP)" The walk took longer than the timeout without producing anything, or the SNMP is wrong. Increase the timeout (up to 240) and validate the SNMP by first creating a simple-model sensor.
sensor_descobrir responds with truncado: true The walk ran out of time but returned partial results. On equipment with many interfaces, increase the timeout.
I created the device but it "monitors nothing" add_device does not create sensors. Create them with add_sensor or turn on the device or group auto-sensor.
Device with this name or IP already exists The duplicate check is global: the same name or the same IP in any group blocks creation.
I edited a ping via API and the ping parameters changed on their own Behavior of edit_sensor with ping sensors: always resend ping_tamanho, ping_quantidade, ping_delay and ping_falhas together.
status_summary of a group came back "empty" but there are devices in subgroups The summary by group_id is not recursive: it only counts devices directly in that group.
One operation responded {"msg": ...} and another {"status": ...} Expected behavior: the two response formats coexist (see the Overview). Handle both in the client and do not rely on the HTTP code alone.
delete_group fails with "Cannot delete group with..." The group is not empty. Move the subgroups with edit_group and the devices with edit_device before deleting.

Other points to watch:

  • The global model search (sensor_modelos with term and no category) is limited to 80 results: refine the term.
  • Names and texts go through HTML sanitization on creation (special characters become entities): avoid HTML in names.
  • The API does not paginate the listings; on very large bases, prefer to cache topology on the client.
  • The key grants full write access to the module (there is no read-only key). Treat the key like a password, use HTTPS and prefer POST so the token does not end up in URL logs.
  • Every write operation via the API goes into the system's Action history (for example "Dispositivo adicionado via API: RB Borda (10.0.0.1)"), visible in the interface.
  • Sensors created via the API enter the normal collection and alert cycle (Telegram, WhatsApp, email, according to the system configuration); nothing extra to configure.