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

Example of list_devices_basic usage #218

Closed oza4h07 closed 3 months ago

oza4h07 commented 3 months ago

Hello,

Could it be possible to include either in the Client.php source code or in examples directory, an example of list_devices_basic usage ?

For instance, I would like to get a list of devices waiting for adoption. Can I get this with list_devices_basic ? If positive, how exactly ?

Best regards

malle-pietje commented 3 months ago

Have a look at the API Browser tool, it will help you understand how the data is structured that is returned for the most common methods: https://github.com/Art-of-WiFi/UniFi-API-browser

The list_devices_basic() method is pretty similar to the list_devices() method and it's use is so easy, you can simply use one of the the other list_xxx() examples.

As the comment in the source code states, the state of the device can be easily be read from the collection you get back from the API. This method helps you map the state codes to human form: https://github.com/Art-of-WiFi/UniFi-API-client/blob/d36a088101e3422e98be1c042afdebaf5f190e8b/src/Client.php#L3370-L3393

oza4h07 commented 3 months ago

I'm sorry but still, I don't understand how it currently works ;-)

For instance, functions list_guests and list_clients have a parameter that is appended at the end of URL and probably used to filter entries.

In list_devices_basic, there is no such parameter. I don't understand how list_devices_basic can list devices "with a basic subset of properties" as it seems, if I'm not mistaken, you can't specify this subset of properties.

I also tried directly typing in a browser the URL bellow but without success (page not found) ../stat/device-basic?state=2 ../stat/device-basic/2

malle-pietje commented 3 months ago

Please create a script based on one of the examples and test this against your own controller. Follow the instruction provided in the README files, the source code and in the example directory. If you run into issues, please share your code and the output with debug mode enabled.

FYI: use of this class does assume you have some basic PHP knowledge.