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_idto 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_sensorof SNMP models andsensor_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).
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".
| Format | Operations | Success | Error |
|---|---|---|---|
| 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
| Concept | What it is |
|---|---|
| Group | Node of the monitoring tree. Groups can contain subgroups and devices. parent_id = 0 means root. |
| Device | Monitored equipment (IP + brand). It belongs to a group (group_id) and has a brand code (equipment). |
| Sensor | A metric monitored within a device. Each sensor is born from a catalog model and has a numeric status (table below). |
| Sensor model | Catalog 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 protocols | 1 = 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 cascade | The 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:
| Code | status_text | Meaning |
|---|---|---|
| 1 | Offline | Sensor with no response. |
| 2 | Paused | Manually paused; not tested and does not alert. |
| 3 | Alert | Alert condition reached. |
| 4 | Critical | Critical condition reached. |
| 5 | Not tested | New or resumed sensor, awaiting the first collection cycle. |
| 6 | OK | Normal. |
| 20 | SNMP failure | The 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.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | int | no (default 100) | Maximum number of alerts returned. |
only_active | bool | no (default false) | "true" returns only alerts not yet resolved. |
group_id | int | no | Filters the alerts by the devices of a group. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=alerts&only_active=true&limit=50"
{"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:
type | type_text |
|---|---|
| 1 | Offline |
| 2 | Paused |
| 3 | Alert |
| 4 | Critical |
| 5 | Not tested |
| 7 | Warning |
| 10 | Critical |
resolvedtells whether the alert is already resolved; in that caseresolved_datecarries the date anddurationis the total time. For active alerts, the duration is counted up to the query moment.duration.formattedcomes asHH: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
notificationsfields (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. totalis how many alerts came in the response;active_count, how many of them are still active.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | yes | Search term (minimum 2 characters). |
type | string | no (default all) | Restricts the type: all, groups, devices or sensors. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=search&query=borda&type=all"
{"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.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
parent_id | int | no (default 0) | Parent group ID. 0 lists the root groups. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_groups&parent_id=0"
{"groups":[{"id":12,"name":"POP Centro","parent_id":0},{"id":15,"name":"Backbone","parent_id":0}]}/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | yes | Root group of the query. |
include_devices | bool | no (default true) | "false" omits the device list of each group (returns only the group structure). |
include_sensors | bool | no (default true) | "false" omits the sensors of each device. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=get_group&group_id=12"
{"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
subgroupsnode repeats the same structure (subgroups,devices,stats), recursively. - In the devices,
equipmentcomes as the brand name (for example"Mikrotik","Outro").list_devicesandget_device, on the other hand, return the brand's numeric code (add_devicetable). - Each sensor carries
id,name,device_id,status,status_text,value(formatted),tag,unitandschedule. Theunitandschedulefields appear only here:list_sensorsdoes not return those two. - Each device also carries a
statusblock summarizing the equipment (fields in the table below). - The
statsblock 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
| Field | Content |
|---|---|
total_sensors | Total sensors of the device. |
sensors_ok | Sensors OK. |
sensors_alert | Sensors in alert (statuses 3 and 7). |
sensors_error | Sensors in error (statuses 4 and 20). |
sensors_offline | Offline sensors (status 1). |
sensors_paused | Paused sensors (status 2). |
overall | Device 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.
/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).
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | yes | Group name. HTML characters are converted to entities. |
parent_id | int | no (default 0) | Parent group. 0 creates at the root. |
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}Errors: Group name is required, Group already exists at this level.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | yes | Group to edit. |
name | string | no | New name. |
parent_id | int | no | Moves the group to another parent. |
ativasnmp | int | no | 2 = the group now has its own SNMP (inherited by the child devices that inherit); any other value = uses the system default. |
snmp_version | int | no | Group SNMP version: 1, 2 or 3. |
snmp_community | string | no | Community (v1/v2c) or user (v3). |
snmp_port | int | no | SNMP port. |
snmp_seclevel / snmp_authproto / snmp_cryptoproto / snmp_authpass / snmp_cryptopass | string | no | SNMPv3 parameters: security level, authentication protocol, encryption protocol and the two passwords. |
latitude / longitude | decimal | no | Map position. Empty or non-numeric values are stored as null. |
autosensor | string | no | The group's auto-sensor template (same value used by the screen; automatic sensor creation on the group's devices). |
autoscan | int | no | Turns the group's Auto-discovery (network scan) on or off. |
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
{"status":"success","group":{"id":77,"nome":"POP Norte 2","idGrupoPai":0}}Errors: group_id is required, Group not found.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | yes | Group to delete. |
curl -s -d "token=KEY&action=dispositivo&operation=delete_group&group_id=77" https://ravi.example.com/api/api.php
{"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.
/api/api.php?action=dispositivo&operation=list_devices
Lists the devices of a group. It is not recursive.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | no (default 0) | Owner group. 0 lists the loose devices at the root. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_devices&group_id=12"
{"devices":[{"id":5,"name":"RB Borda","ip":"10.0.0.1","group_id":12,"equipment":2}]}/api/api.php?action=dispositivo&operation=get_device
Returns a device with all its sensors (same sensor format as list_sensors).
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Device to query. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=get_device&device_id=5"
{"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.
/api/api.php?action=dispositivo&operation=status_summary
Status counters for external dashboards: total devices, total sensors and sensors by state.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | no | If sent, considers only the devices directly inside that group (does not descend into subgroups). Without it, the whole system. |
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}}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.
/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 -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=topology"
{"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=0is 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.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | yes | Device name. |
ip | string | yes | Valid IP (IPv4 or IPv6). |
group_id | int | no (default 0) | Owner group. 0 creates at the root. |
equipment | int | no (default 100) | Brand code (table below). |
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}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.
| Code | Brand | Code | Brand |
|---|---|---|---|
| 1 | Ubiquiti | 12 | Cambium Networks |
| 2 | Mikrotik | 13 | Ceragon |
| 3 | Cisco | 14 | VOLT |
| 4 | Juniper | 15 | XPS |
| 5 | Huawei | 16 | ALGcom |
| 6 | Fiberhome | 17 | Rondotec |
| 7 | ZTE | 18 | Linux |
| 8 | Intelbras | 19 | DATACOM |
| 9 | PARKS | 20 | JFA |
| 10 | v-Solution | 21 | a10 |
| 11 | Mimosa | 100 | Other |
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Device to edit. |
name | string | no | New name. |
ip | string | no | New IP (validated; invalid returns Invalid IP address). |
group_id | int | no | Moves the device to another group. |
equipment | int | no | Changes the brand (codes from add_device). |
herdar_snmp | int | no | 2 = the device uses its own SNMP (the snmp_* fields below); any other value = inherits from the group or the system. |
snmp_version | int | no | 1, 2 or 3. |
snmp_community | string | no | Community (v1/v2c) or user (v3). |
snmp_port | int | no | SNMP port. |
snmp_seclevel / snmp_authproto / snmp_cryptoproto / snmp_authpass / snmp_cryptopass | string | no | SNMPv3 credentials. |
herdar_ssh | int | no | Analogous to SNMP, for the device's own SSH credentials. |
ssh_user / ssh_pass / ssh_port | string | no | Device SSH credentials (used in the per-device terminal, backups, etc.). |
limit_snmpget | int | no | Limit of OIDs per SNMP query, for equipment that does not accept large queries. |
inf | string | no | Information field (free-form notes). |
inf_sigilosas | string | no | Confidential notes field (visible according to the screen permission). |
auto_sensor | int | no | 0 turns off automatic sensor creation for this device; 1 or 2 turns it on. |
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
{"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.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Device to delete. |
curl -s -d "token=KEY&action=dispositivo&operation=delete_device&device_id=123" https://ravi.example.com/api/api.php
{"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).
/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).
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Owner device. |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=list_sensors&device_id=5"
{"sensors":[{"id":301,"name":"Carga de CPU","device_id":5,"status":6,"status_text":"OK","value":"12%","tag":"cpuMikrotik"}]}Error: Device ID is required.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to query. |
curl "https://YOUR-SERVER/api/api.php?action=dispositivo&operation=get_sensor&sensor_id=8623&token=YOUR_TOKEN"
{"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}}}valuescarries one item per active collector, each withname,raw_value,extension(unit) andaverage;raw_valuesandaveragesexpose the four raw fields (value1..4andavg1..4).statusfollows the status table in the Overview;status_textis the label in the system language.modelidentifies the source catalog model.- The
contextfield 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 (descricaofield) and the condition data. A normal sensor (no active message) comes without thecontextfield.
Errors: Sensor ID is required, Sensor not found.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to query. |
start_date | date | no (default today) | Start date in YYYY-MM-DD format. |
end_date | date | no (default today) | End date in YYYY-MM-DD format. |
include_stats | bool | no (default true) | "false" omits the statistics block. |
limit | int | no (default 0) | Maximum records returned in data. 0 = no limit. |
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"
{"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
dataitem carries thetimestamp, the reading'sstatus/status_textand thevaluesper collector (name, value and unit). total_recordsis how much exists in the range;returned_recordsis how much came after applyinglimit.- 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_summarycounts 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.
/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).
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Owner device. |
model_id | int | yes | Catalog model (accepts the alias idSensor). |
grupo_sensor_id | int | no | Sensor group (tab) where the sensor goes in the device panel. |
alvos | JSON array | ping only | Several targets at once: [{"ip":"8.8.8.8","nome":"Google"}]. |
ping_ip / ping_nome | string | ping 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. |
nome | string | aggregator only | Aggregator sensor name. |
ids | CSV string | aggregator only | IDs of the source sensors (minimum 2, all of the same type). |
itens | JSON array | interface only | Items 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). Withoutitens, 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 -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{"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.
/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).
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to edit. |
nome | string | no | New name (cannot be empty if sent). |
valor | string | no | The sensor's "valor" field (interface index, ping IP, etc.). Be careful when changing it. |
cronograma | string | no | Collection interval: 30s, 1m (recommended default), 5m, 15m, 1h, 1d, 7d. |
falhas | string | no | (Non-ping sensors) failure threshold before alarming. |
ping_tamanho | int | see warning | (Ping only) packet size in bytes. Default 32. |
ping_quantidade | int | see warning | (Ping only) number of packets. Default 20. |
ping_delay | int | see warning | (Ping only) interval between packets. Default 1. |
ping_falhas | int | see warning | (Ping only) tolerated failures. Default 2. |
display_tipo | int | no | 1 = show 1 value; 2 = show 2 values (for example down/up). |
display_separador | string | no | Separator between the 2 values (maximum 4 characters, default " / "). |
display_valor1 / display_valor2 | int | no | Which 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 -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
{"status":"success"}Errors: sensor_id is required, Sensor not found, nome obrigatorio.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to pause. |
curl -s -d "token=KEY&action=dispositivo&operation=pause_sensor&sensor_id=501" https://ravi.example.com/api/api.php
{"msg":"ok"}Errors: Sensor ID is required, Sensor not found.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to resume. |
curl -s -d "token=KEY&action=dispositivo&operation=resume_sensor&sensor_id=501" https://ravi.example.com/api/api.php
{"msg":"ok"}Errors: Sensor ID is required, Sensor not found.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
sensor_id | int | yes | Sensor to delete. |
curl -s -d "token=KEY&action=dispositivo&operation=delete_sensor&sensor_id=501" https://ravi.example.com/api/api.php
{"msg":"ok"}Errors: Sensor ID is required, Sensor not found.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Device whose sensors will all be deleted. |
curl -s -d "token=KEY&action=dispositivo&operation=delete_all_sensors&device_id=123" https://ravi.example.com/api/api.php
{"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.
/api/api.php?action=dispositivo&operation=sensor_categorias
Lists the categories of the sensor catalog (including the brand groups), already in the system language.
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | no | If sent, also returns the device's IP (useful to pre-fill the ping target). |
curl -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=sensor_categorias&device_id=123"
{"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.
/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
group_id | int | no | ID of the category (coming from sensor_categorias). Note: here group_id is a catalog category, not a tree group. |
term | string | no | Search 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 -s "https://ravi.example.com/api/api.php?token=KEY&action=dispositivo&operation=sensor_modelos&group_id=4&term=trafego"
{"status":"success","models":[{"id":45,"nome_pt":"Tráfego de interface","tag":"ifMikrotik","protocolo":1,"tipo":2}]}/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.
| Parameter | Type | Required | Description |
|---|---|---|---|
device_id | int | yes | Target device. |
model_id | int | yes | Interface model from the catalog. |
timeout | int | no (default 60) | Seconds (minimum 5, maximum 240). If it overflows, it returns what it collected with truncado: true. |
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
{"status":"success","itens":[{"index":"7","nome":"sfp-sfpplus1","valor1":"..."}],"total":48,"truncado":false}- The
indexcan 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
# 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 -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 -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.
| Symptom | Likely 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_modeloswithtermand 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
topologyon 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.