nickovs / unificontrol

A high-level Python interface to the Unifi controller software
Apache License 2.0
96 stars 41 forks source link

trying to create wlan networks #27

Open mrgiesz opened 3 years ago

mrgiesz commented 3 years ago

I'm trying to generate a few wifi networks. In my limited python knowledge i've copied and modified the create_network to:

create_wlan = UnifiAPICall(
    "Create a wifi network",
    "rest/wlanconf",
    json_body_name='settings',
    method="POST",
    )

Now when i try to create a test network i get the following error:

Traceback (most recent call last): File "<pyshell#188>", line 1, in client.create_wlan(settings={'name': 'test1200_Office', 'usergroup_id': '60f9488e46e0fb012814562b', 'wlangroup_id': '60f9488e46e0fb012814562c', 'enabled': True, 'hide_ssid': False, 'is_guest': False, 'security': 'wpapsk', 'wpa_mode': 'wpa2', 'wpa_enc': 'ccmp', 'vlan_enabled': True, 'uapsd_enabled': False, 'x_passphrase': 'supergeheimwachtwoord', 'schedule_enabled': False, 'schedule': [], 'vlan': 10}) File "C:\Users\marijn\AppData\Roaming\Python\Python39\site-packages\unificontrol\metaprogram.py", line 125, in wrapper return instance(client, *a, **kw) File "C:\Users\marijn\AppData\Roaming\Python\Python39\site-packages\unificontrol\metaprogram.py", line 103, in call return client._execute(url, self._method, rest_dict, need_login=self._need_login) File "C:\Users\marijn\AppData\Roaming\Python\Python39\site-packages\unificontrol\unifi.py", line 115, in _execute raise UnifiTransportError("{}: {}".format(resp.status_code, resp.reason)) unificontrol.exceptions.UnifiTransportError: 400:

Any ideas what i'm doing wrong?

Thanks

mrgiesz commented 3 years ago

I'm a step further, Seems like the value i was missing is the ap_group_ids, which on a new site without wifi networks are not yet in the wlanconf.

I'm now trying to figure out where i can get this value on a new site.

nickovs commented 3 years ago

Thanks for looking into implementing new calls. Since Ubiquiti still don't document their API this can be a somewhat tedious process. In general the best option I've found is to open up the the debug tools in your web browser while using the Unifi controller web interface and examine the requests that their JavaScript UI makes.

mrgiesz commented 3 years ago

By looking at the debug tools, there seems to be a way to create a new wlan group. it's posting to https://controller-ip:10443/v2/api/site/zdypdga4/apgroups

{ "_id": "60f97979a13fe06510c85bb7", "attr_no_delete": false, "device_macs": [], "name": "test" }

mrgiesz commented 3 years ago

It looks like I need to first create one, however i'm having some difficulties adding another api call which will get the current ap_group_ids, (which can be seen at: https://10.9.28.10:8443/v2/api/site/rr575ua3/apgroups), and post the new ap group to that url as well.

But i don't really understand how the unifiapicall function works, Would you be able to point me in the right direction?

What i did was add:

list_ap_groups = UnifiAPICall(
    "List ap groups",
    "/apgroups",
    )

and

create_ap_group = UnifiAPICall(
    "Create an ap group",
    "apgroups",
    json_body_name='settings',
    method="POST",
    )
pnemmalysha commented 8 months ago

By looking at the debug tools, there seems to be a way to create a new wlan group. it's posting to https://controller-ip:10443/v2/api/site/zdypdga4/apgroups

{ "_id": "60f97979a13fe06510c85bb7", "attr_no_delete": false, "device_macs": [], "name": "test" }

Just want to thank you for your research. Very helpful link!