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

Unable to use Create_WLAN #159

Closed bill-cli closed 4 months ago

bill-cli commented 2 years ago

Attempting to create a new WLAN according to documentation in client.php. See following code:

/**
 * PHP API usage example
 *
 * contributed by: Art of WiFi
 * description:    example basic PHP script to create a new site, returns true upon success
 */

/**
 * using the composer autoloader
 */
// require_once 'vendor/autoload.php';
require_once 'C:/Users/admin/Downloads/UniFi-API-client-1.1.79/src/client.php';
/**
 * include the config file (place your credentials etc. there if not already present)
 * see the config.template.php file for an example
 */
require_once '../config.php';

/**
 * we use the default site in the initial connection
 */
/**
 * the site to use to log in to the controller
 */
$site_id = 'default';

/**
 * description of the new site
 */
$name ='APITest';
$x_passphrase ='PlacePasswordHere';
$usergroup_id ='id from list_usergroup';
$wlangroup_id ='id from list_wlan_group';
/*$enabled = true;
$hide_ssid = false; 
$is_guest = false; 
$security = 'open'; 
$wpa_mode = 'wpa2'; 
$wpa_enc = 'ccmp'; 
$vlan_enabled = null; 
$vlan_id = null; 
$uapsd_enabled = false; 
$schedule = [];
$schedule_enabled = false;
$ap_group_ids = null; */

/**
 * initialize the UniFi API connection class and log in to the controller and do our thing
 */
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
$loginresults     = $unifi_connection->login();
$results          = $unifi_connection->create_wlan($name, $x_passphrase, $usergroup_id, $wlangroup_id/*, $enabled, $hide_ssid, $is_guest, $security, $wpa_mode, $wpa_enc, $vlan_enabled, $vlan_id, $uapsd_enabled,$schedule,$schedule_enabled,$ap_group_ids*/);
$debug            = $unifi_connection->get_debug();
/**
 * provide feedback in json format
 */
echo json_encode($results, JSON_PRETTY_PRINT);
echo json_encode($debug, JSON_PRETTY_PRINT);

Debug is enabled. This function results in the output "false", debug output is also "false".

We tailed the logs in the docker container running the controller (7.1.65) and the server.log file generates this message:

<webapi-83> WARN sanitize - Invalid key exists in WlanConf payload, key=wlangroup_id

malle-pietje commented 2 years ago

Which value are you passing as the wlangroup_id?

bill-cli commented 2 years ago

The client documentation says to pass one retrieved from the “list_wlan_groups”, so i pass the “_id” parameter from that command.

On Wed, May 25, 2022 at 4:39 PM malle-pietje @.***> wrote:

Which value are passing as the wlangroup_id?

— Reply to this email directly, view it on GitHub https://github.com/Art-of-WiFi/UniFi-API-client/issues/159#issuecomment-1137826094, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVYZVUIFZA5N5KWWMVG3DJLVL2FYDANCNFSM5W56JRFQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Bill Meaney, CTS-D, CTS-I Network Engineer/Developer CommLink Integration Corp. 5 Strathmore Road, Natick, MA 01760 Office 617-982-0740 Fax 508-650-5124

malle-pietje commented 2 years ago

Ok, understood, just checking. I don’t have the time at the moment but need to check if anything changed with this route for the latest controller versions. Maybe that parameter is no longer needed or renamed.

karpiatek commented 1 year ago

Well, starting from version 6 of the UniFi controller, there is no longer such parameter as wlangroup_id.

malle-pietje commented 1 year ago

If anyone is willing to submit a pull request or share a code change here I will test and incorporate it in the mainstream package.

OrionTheGiant commented 1 year ago

I watched the browser network console when adding a new WiFi network on version 7.2.92 of the controller application and it looks like the API endpoint may have changed as well. The POST is going to /rest/wlanconf instead of /add/wlanconf in addition to wlangroup_id not being included. I'll try to test the changes and make a pull request this week.

OrionTheGiant commented 1 year ago

Removing the wlangroup_id and changing the API endpoint worked. Pull request in #169

swapnildevstree commented 6 months ago

Can anyone please give complete working example of the Latest function and code without wlan group id