Closed RedAxoul closed 8 years ago
Probably your mistake is caused by lack of documentation: for the create_voucher($minutes, $number_of_vouchers_to_create = 1, $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL)
function all parameters except $note
are numeric so should be passed without (double) quotes. Let me know if that fixes the issue.
EDIT: changed important typo "with" to "without" :-(
I tried whith the following code too : //variables $voucherlength=1440; $number=1; $notes="test"; $up=512; $down=2500; $mb=10000;
$unifidata->create_voucher($voucherlength, $number, $notes, $up, $down, $mb);
But still not fixes the issue :(
I just had a better look at the response you're getting and that looks fine: you're getting create time in the json response which is the create time for the newly created vouchers. Did you check whether they show up in your controller hotspot?
With the page stalling, probably something is wrong in how you're handling the response. Can you share the code you're using after the $unifidata->create_voucher($voucherlength, $number, $notes, $up, $down, $mb);
line?
It looks as if I need to update the comments for the create_voucher
function to reflect the fact that the response contains the create time instead of an array containing voucher codes. That changed in one of the recent controller releases if I'm not mistaken. Which controller version are you using @RedAxoul ?
Yep, vouchers are goodly created in the controller hotspot.
Controller version is 4.8.15.
Concerning code used right after, I tried these : $vouchers = $unifidata->create_voucher($voucherlength, $number, $notes, $up, $down, $mb); print_r($vouchers);
and : $unifidata->create_voucher($voucherlength, $number, $notes, $up, $down, $mb); echo "test";
or even nothing right after, dunno what I am supposed to do right after the create_vouchers function :D
(At the end, I will want to get the voucher code created to print it.)
Thank for trying to help me, I have to go but will come back so don't worry if I don't answer right now ;)
So I tried to download all you project to see if I was having a problem in my code or if it's something else.
I edited the variables to have the good infos, then I modified the index.php and added only this line : $unifidata->create_voucher(1440, 1, "test", 500, 500, 1000);
And then I got a full white page whitout anymore the menu :( (But the voucher is created in the Controler Hotspot)
Also tried an upgrade of the controller in version : 4.8.20. Curl version is : 7.45.0 And PHP is : 5.6.24
Did I miss something ? :o
I think I found the issue !!! (Tested with WAMP instead of the VM with LAMP and got the error about "get_vouchers() is undefined")
In the API the create voucher function have this line : foreach ($this->get_vouchers($obj->create_time) as $voucher) { And it should be replaced by : foreach ($this->stat_voucher($obj->create_time) as $voucher) {
Hope that it can help others people that encounter the same issue, and thank you for that super API :D
Thanks for the catch, must have been introduced with the name change of the function.
@RedAxoul FYI: the function has now been fixed with the commit for API client version 1.0.6. Thanks for your help in identifying the issue!
Hi malle-pietje,
First, thank you for that great api ! :D
I am currently trying your class.unifi.php but got a problem with the voucher creation, when I am creating a voucher my page is hanging just after the voucher creation
I am using the following code for a simple voucher creation : $unifidata->create_voucher("1440", "1"); echo "test";
My voucher is goodly created in the controler, but page is hangins there and so test is never displayed, as the rest of my code is not executed too :(
(Just for info : got no problem to list vouchers, add site, list site, etc ... Just stuck on that voucher creation :( What did I miss ? )
I enabled debug mode and got this thing if it can help :
-----cURL INFO--------------- Array ( [url] => https://192.168.70.128:8443/api/s/j2nu4f1a/cmd/hotspot [content_type] => application/json;charset=UTF-8 [http_code] => 200 [header_size] => 178 [request_size] => 302 [filetime] => -1 [ssl_verify_result] => 18 [redirect_count] => 0 [total_time] => 0.023527 [namelookup_time] => 3.3E-5 [connect_time] => 0.000414 [pretransfer_time] => 0.020651 [size_upload] => 53 [size_download] => 70 [speed_download] => 2975 [speed_upload] => 2252 [download_content_length] => 70 [upload_content_length] => 53 [starttransfer_time] => 0.023495 [redirect_time] => 0 [redirect_url] => [primary_ip] => 192.168.70.128 [certinfo] => Array ( )
)
-----URL & PAYLOAD----------- https://192.168.70.128:8443/api/s/j2nu4f1a/cmd/hotspot json={"cmd":"create-voucher","expire":"1440","n":"1"} -----RESPONSE----------------
{ "data" : [ { "create_time" : 1472119403}] , "meta" : { "rc" : "ok"}}
Thanks in advance