API SDK

Read 4957 times
Where do we get some examples? Namely the SDK

I mean, to create accounts using the API, no doubt you have to provide an username and password. Do we use our admin credentials for system and server class method? Or just system class?

eg. json
Quote
:2199/api.php?xm=system.provision&f=json&username=admin&password=blah&restofitems=blah
Last Edit: March 14, 2016, 06:35:26 am by LawsHosting
Please someone help me here

I always get
Quote
{"type":"error","response":{"message":"Invalid username or password"}}

My curl function
Code: [Select]
    function call($params)
    {
        Lib::log(4, '> CentovaCast Params : ' . print_r($params, true));

        $ch = curl_init();
        curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->password}");
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_URL, $this->url);

        $data = curl_exec($ch);

        Lib::log(4, '< CentovaCast Params : ' . print_r($data, true));

        if ( $data === false )
        {
            $error = "CentovaCast API Request / cURL Error: ".curl_error($ch);
            Lib::log(4, $error);
            throw new Exception($error);
        }

        $data = json_decode($data);
        curl_close($ch);

        if ( $data->type == 'success' ) {
            return $data;
        } else if ( $data->type == 'error') { // && $data->response !== 'Invalid username or password') {
            throw new Exception('CentovaCast Error : '.$data->response->message);
        }
    }

Example $params
Quote
Array
(
    [xm] => server.enabled
    [f] => json
    [a[username]] => laws
)
Which is turned into
Quote
xm=server.enabled&f=json&a[username]=laws