Solved

Encode json with cURL to an API help

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
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…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

920 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

15 Experts available now in Live!

Get 1:1 Help Now