tb78
18 June 2024 15:46
1
I am trying to do a simple “add device to group” via the API per the documentation at:
I am not having success. My group name is “Servers” and show’s up in the devicegroups endpoint:
$ curl -H ‘X-Auth-Token: ’ http://:8000/api/v0/devicegroups/
{
“status”: “ok”,
“groups”: [
{
“id”: 1,
“name”: “Servers”,
“desc”: null,
“type”: “static”,
“rules”: {
“condition”: null,
“rules”: ,
“valid”: true,
“joins”:
},
“pattern”: null
}
],
“message”: “Found 1 device groups”,
“count”: 1
}
However when adding a device to the group per the documentation, the route is invalid:
$curl -H ‘X-Auth-Token: ’ -X POST http://:8000/api/v0/devicegroups/Servers/devices -d ‘{“devices”:[78]}’
{
“status”: “error”,
“message”: “This API route doesn’t exist.”
}
Version info as follows:
|Version |[23.11.0 - Sat Nov 25 2023 14:17:34 GMT-0500]
|Database Schema |2023_11_04_125846_packages_increase_name_column_length (273)|
|Web Server ||
|PHP |8.1.22|
|Python |3.10.13|
|Database |MariaDB 10.5.23-MariaDB-1:10.5.23+maria~ubu2004|
|Laravel |10.16.1|
|RRDtool |1.7.2|
tb78
18 June 2024 16:05
2
Also I believe there may be a typo in the documentation, it shows the route as:
/api/v0/devices groups/:name/devices
…but the example shows:
/api/v0/devicegroups/devices
I assume “devicegroups” is correct, but neither work for me.
It looks like you are correct, should be devicegroups. So the curl example is good but the route piece of the doc is wrong. It also looks like this was added in late Jan. of 2024 in the following PR. So you’re version is a few months too old.
librenms:master
← richard-ririe:device-groups-static-devices
opened 12:00PM - 23 Jan 24 UTC
Creates API endpoints to allow devices to be added to or removed from Device Gro… ups that have type = "static".
DO NOT DELETE THE UNDERLYING TEXT
#### Please note
> Please read this information carefully. You can run `./lnms dev:check` to check your code before submitting.
- [x] Have you followed our [code guidelines?](https://docs.librenms.org/Developing/Code-Guidelines/)
- [x] If my Pull Request does some changes/fixes/enhancements in the WebUI, I have inserted a screenshot of it.
- [x] If my Pull Request makes discovery/polling/yaml changes, I have added/updated [test data](https://docs.librenms.org/Developing/os/Test-Units/).
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
tb78
18 June 2024 16:56
4
That explains it - thanks.
tb78
18 June 2024 17:12
5
Updating did resolve the issue. However the example in the docs is incorrect:
-X POST https://librenms.org/api/v0/devicegroups/devices
…should be:
-X PATCH http://librenms.org/api/v0/devicegroups/:name/
tb78
18 June 2024 17:17
6
Well, now I’m confused.
The PATCH I showed above replaces everything in the group with whatever new devices you specify. I am unable to figure out how to add a new device to an existing group…
PATCH calls update_device_group, POST calls update_device_group_add_devices. I’m able to add a device with POST.
~ % curl -H 'X-Auth-Token: d72b64d6649141ac022e497700e45953' http://localhost:8000/api/v0/devicegroups/
{
"status": "ok",
"groups": [
{
"id": 1,
"name": "New",
"desc": "new static group",
"type": "static",
"rules": null,
"pattern": null
}
],
"message": "Found 1 device groups",
"count": 1
}%
~ % curl -H 'X-Auth-Token: d72b64d6649141ac022e497700e45953' http://localhost:8000/api/v0/devicegroups/New
{
"status": "ok",
"devices": [
{
"device_id": 2
}
],
"count": 1
}%
~ % curl -H 'X-Auth-Token: d72b64d6649141ac022e497700e45953' -X POST http://localhost:8000/api/v0/devicegroups/New/devices -d '{"devices":[1]}'
{
"status": "ok",
"message": "Devices added"
}%
~ % curl -H 'X-Auth-Token: d72b64d6649141ac022e497700e45953' http://localhost:8000/api/v0/devicegroups/New
{
"status": "ok",
"devices": [
{
"device_id": 1
},
{
"device_id": 2
}
],
"count": 2
}%
tb78
18 June 2024 17:49
8
Thank you! Good to go now.
1 Like
system
Closed
16 September 2024 17:49
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.