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);

        return $output;

And I call it with
Code: Select all
for the moment.

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

Re: Calling WebAPI in PHP via cURL

Postby jenn2321 on Mon Apr 09, 2018 4:48 am

Hi,I have read through some similar topics! However, your post has given me a very special impression, unlike other posts. I hope you continue to have valuable articles like this or more to share with everyone.
Posts: 1
Joined: Mon Oct 23, 2017 9:50 am

Return to Zend Server for IBM i

Who is online

Users browsing this forum: No registered users and 1 guest