Art-of-WiFi / UniFi-API-client

A PHP API client class to interact with Ubiquiti's UniFi Controller API
MIT License
1.09k stars 217 forks source link

List Devices has an API v2 call #155

Closed Sieberkev closed 4 months ago

Sieberkev commented 2 years ago

Hello,

First and foremost thank you for making/maintaining this API!

Currently I am using:

When embarking on a quest to search for more control over my Protect Devices (especially changing the Recording Mode dynamically based on certain criteria, instead of only having geofenced alerts), I was quickly blocked by having the current list_devices() function only returning Network devices.

But delving down the Console DevTools, I found out that in this version there is a updated call https://192.168.1.1/proxy/network/v2/api/site/default/device which returns a JSON object with an array per (access|connect|led|network|protect|talk)_devices.

image

The original v1 call only seems to return a slightly different network_devices array (I think there are some new/renamed keys).

Locally I can extend the class to use the new API path for now, but maybe this can be implement in the official client? I could try to make a PR but do not know the best practice to implement this without breaking existing functionality (new function ex list_all_devices() or list_devices_v2()? new parameter to indicate which version to use?)

thib3113 commented 2 years ago

Hello @Sieberkev , I've done some search about this list Device Api V2 . but for another project . I doesn't have the time to continue, it, but doesn't hesitate to get informations : https://github.com/thib3113/unifi-client/pull/243

It's in node.js / typescript . but Maybe you can grab some usefull informations .

Typing of what the endpoint return : https://github.com/thib3113/unifi-client/pull/243/files#diff-4dbefe4fa921e0d30c520a54bc1c6109e23ab3ec5674566d4e1533a80a6d9ddbR26 ( and follow the differents types )


On my project, I choose to replace the call, depending of the controller version . But always allow the previous call ( If I correctly remember, some datas are not available in the new endpoint ) .

malle-pietje commented 2 years ago

I’m aware of the different routes for the various apps, we’ve done some small stuff with Protect which actually works quite nicely.

For your example it is pretty easy to use the custom request method as listed here: https://github.com/Art-of-WiFi/UniFi-API-client/blob/master/src/Client.php#L3165

The API client will then still handle the login/auth etc for you.

malle-pietje commented 2 years ago

Just as a note here: we have no plans to add Protect/Connect/etc related methods to the client. The class is focused purely on the Network Application/Controller. Feel free to create your own fork that adds methods for the other Applications.

thib3113 commented 2 years ago

@malle-pietje this new route is part of the network . Just returning unifi devices in other way ( before it return only network devices, now all the unifi devices are returned ) .

malle-pietje commented 2 years ago

Understood, but at this stage I’m still hesitant to add a method for this endpoint. For now it would be great if you can share an example using the custom method.