Solved

Encode json with cURL to an API help

Posted on 2015-02-11
3
354 Views
Last Modified: 2015-02-19
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-guest', 'mac':'${mac}', 'minutes':${minutes}${other_payload}}" $baseurl/api/s/$site/cmd/stamgr
}

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,
0
Comment
Question by:Jesper Andersen
  • 2
3 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 40609245
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?
0
 

Accepted Solution

by:
Jesper Andersen earned 0 total points
ID: 40609839
I got the solution... there was a bug in the firmware on the Access Points. After new firmware from the manufactor, everything worked fine with the above php code.

Closing...
0
 

Author Closing Comment

by:Jesper Andersen
ID: 40618476
I found a solution to the problem myself...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now