Jesper Andersen
asked on
Encode json with cURL to an API help
Hello Guys,
I am having a little problem with a Unifi Controller that I am trying to communicate with through PHP.
The API documentation for the controller is located here: http://dl.ubnt.com/unifi/4.6.0/unifi_sh_api
And the function I'm trying to use is to authenticate a user.
# cmd/stamgr
# authorize-guest(mac, minutes, [up=kbps, down=kbps, bytes=MB])
unifi_authorize_guest() {
if [ $# -lt 2 ] ; then
echo "Usage: $0 <mac> <minutes> [up=kbps] [down=kbps] [bytes=MB] [ap_mac=mac]"
return
fi
mac=$1
minutes=$2
other_payload=`named_args_ to_payload "$@"`
${curl_cmd} --data "json={'cmd':'authorize-gu est', 'mac':'${mac}', 'minutes':${minutes}${othe r_payload} }" $baseurl/api/s/$site/cmd/s tamgr
}
I got it working with the first 3 commands, but I cant get upload, download and quota to work.
This is how I do it now:
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes));
I hoped that I could just do it like this, but it doesnt work :-( Am I dont know about this kind of programmering.
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes,
'up'=>$upload,
'down'=>$download));
So I hope some of you guys can help me out here, and tell me how the string to the controller should look like to get it working.
Thanks,
I am having a little problem with a Unifi Controller that I am trying to communicate with through PHP.
The API documentation for the controller is located here: http://dl.ubnt.com/unifi/4.6.0/unifi_sh_api
And the function I'm trying to use is to authenticate a user.
# cmd/stamgr
# authorize-guest(mac, minutes, [up=kbps, down=kbps, bytes=MB])
unifi_authorize_guest() {
if [ $# -lt 2 ] ; then
echo "Usage: $0 <mac> <minutes> [up=kbps] [down=kbps] [bytes=MB] [ap_mac=mac]"
return
fi
mac=$1
minutes=$2
other_payload=`named_args_
${curl_cmd} --data "json={'cmd':'authorize-gu
}
I got it working with the first 3 commands, but I cant get upload, download and quota to work.
This is how I do it now:
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes));
I hoped that I could just do it like this, but it doesnt work :-( Am I dont know about this kind of programmering.
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes,
'up'=>$upload,
'down'=>$download));
So I hope some of you guys can help me out here, and tell me how the string to the controller should look like to get it working.
Thanks,
The code you've posted seems to be a mix of shell scripting and php. Are you trying to convert the API to php or just trying to utilise it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a solution to the problem myself...