Centova Technologies Forum

Centova Cast v3 => General discussion => Topic started by: LawsHosting on March 14, 2016, 06:23:00 am

Title: API SDK
Post by: LawsHosting on March 14, 2016, 06:23:00 am
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
Title: Re: API SDK
Post by: LawsHosting on March 15, 2016, 04:35:10 am
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