Calling WebAPI in PHP via cURL

General discussion on Zend Server for IBM System i
Post Reply
Posts: 1
Joined: Fri Dec 15, 2017 4:13 pm

Calling WebAPI in PHP via cURL

Post by loï6183 » 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: 2
Joined: Mon Oct 23, 2017 9:50 am

Re: Calling WebAPI in PHP via cURL

Post by jenn2321 » 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: Tue May 08, 2018 9:59 am

Re: Calling WebAPI in PHP via cURL

Post by mark7626 » Tue May 08, 2018 9:59 am

Hi, your blog is truly flawless and unique. Good content, but it would be better if in future you can talk about more about this subject. Really very perfect your article and blog post.

User avatar
Zend Global Services
Posts: 34
Joined: Sat Jun 30, 2012 9:59 pm
Location: United States

Re: Calling WebAPI in PHP via cURL

Post by clarkphp » Thu May 17, 2018 5:21 pm


You may wish to use the DeploymentHelper, or the ZendServerSDK, both of which make it easier to deploy applications via the WebAPI. The ZendServerSDK can also be used to access other WebAPI methods besides deployment, from the command line.

Zend Server 6.3 is quite old, indeed, and is no longer supported. I strongly suggest you upgrade to a current version (Zend Server 8.5 for PHP 5.6, or Zend Server 9.1 for PHP 7.1).

Clark Everetts
Zend Professional Services Consultant
Rogue Wave Software

Post Reply