Solved

Encode json with cURL to an API help

Posted on 2015-02-11
3
378 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 43

Expert Comment

by:Rob
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

791 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