Solved

Encode json with cURL to an API help

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

713 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