Calling WebAPI in PHP via cURL

General discussion on Zend Server for IBM System i

Calling WebAPI in PHP via cURL

Postby loï6183 on Fri Dec 15, 2017 4:24 pm

Hi !

I want to create a PHP script to automatically deploy my application, but I don't manage to make the WebAPI work... Everytime I try, either I receive the "login" page of the UI or I receive a "connexion refused". I tried calling a simple route with no parameters (jobqueueStatistics) but I can't make it work, and the documentation isn't very helpful...
I use Zend Server Version 6.3.0, Professional Edition.

Here is my PHP function :

Code: Select all
function callAPI($action)
{
        $ch         = curl_init();
        $path      = '/ZendServer/Api/' . $action; //I'm not even sure about the path
        $host      = $_SERVER['HTTP_HOST'];
        $time      = strftime('%a, %d %b %Y %H:%I:%S') . ' GMT';
        $userAgent = $_SERVER['HTTP_USER_AGENT'];

        curl_setopt($ch, CURLOPT_URL, 'http://xxx.yyy.zzz:10081' . $path); //Returns the login page with port 10081,cURL fails with port 10083
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'X-Zend-Signature: developer;' . generateRequestSignature($host, $path, $time, $userAgent, 'MY_KEY_FOR_DEVELOPER_FOUND_IN_THE_UI'),
            'Date: ' . $time,
            'User-Agent: ' . $userAgent,
            'Host: ' . $host,
        ));
        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
}


And I call it with
Code: Select all
callAPI('jobqueueStatistics');
for the moment.

Do I do this wrong ? Is there something to configure beforehand ? I'm a bit lost...
loï6183
 
Posts: 1
Joined: Fri Dec 15, 2017 4:13 pm

Return to Zend Server for IBM i

Who is online

Users browsing this forum: No registered users and 3 guests

cron