VMware Cloud Community
deepthy
Enthusiast
Enthusiast
Jump to solution

Execute workflow using SOAP API through PHP

Hi,

I am trying to integrate workflows from PHP code using the orchestrator SOAP API.

<?php

try

{

$parameters=array(username=>"username",password=>"passwd");

$client = new SoapClient('https://vcoserver:8281/vco/vmware-vmo-webcontrol/webservice?WSDL');

$result = $client->getAllWorkflows($parameters);

foreach($result as $item)

{

        foreach($item as $work)

     {

        echo $work->name;

        echo "<br>";

         echo "id";

        echo $work->id;

     echo "<br />";

     }

}

}

catch(Exception $e)

{

        echo  $e;

}

?>

I do not see any error/exception, but do not see any output as well.

Am i missing anything?

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Could you use

print curl_error($curl);

after curl_exec to check if there are some errors?

If there is some SSL certificate error, like 'SSL certificate problem: unable to get local issuer certificate', you can either install root certificates (Google for information how to do so), or disable verification of peer certificates in CURL with something like:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

View solution in original post

Reply
0 Kudos
21 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

This is not the answer you are expecting but the SOAP API is going to be deprecated. I am not sure how you can use the REST API from PHP but if you need to invest your time it should be with REST.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

Thanks for the heads-up.  Smiley Happy

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I tried your code as-is and it worked just fine (on Windows 7 + PHP 5.4.26 + vCO 5.5.1).

What happens if you open SOAP API URL in a browser https://vcoserver:8281/vco/vmware-vmo-webcontrol/webservice?WSDL ?

Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

I can see the WSDL in the browser.

But still facing the same issue.  I am not sure if I am missing any dependencies.

On the other hand, is it true that SOAP API are going to be deprecated? If so, I don't want to invest effort trying this.

Please suggest

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, the current plan is to deprecate SOAP API soon and remove them later, probably around 2016.

Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

In that case, can you please help me achieve the same with REST API?

Can you please share a sample code?

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

I have very limited PHP knowledge, but something like this should work:

<?php

try

{

  $cred = sprintf('Authorization: Basic %s', base64_encode("myusername:mypassword") );

  $opts = array(

   'http'=>array(

     'method'=>'GET',

     'header'=>$cred)

  );

  $url='https://vcoserver:8281/vco/api/workflows'; // vCO 5.5 REST API to get all workflows

  $ctx = stream_context_create($opts);

  $handle = fopen($url, 'r', false, $ctx);

  $response = stream_get_contents($handle);

  $result = json_decode($response);

  foreach($result as $item)

  {

     foreach($item as $work)

     {

        var_dump( $work );

     }

  }

}

catch(Exception $e)

{

    echo  $e;

}

?>

Reply
0 Kudos
demhyt
Contributor
Contributor
Jump to solution

Hi Deepthy try this

/*parameters.inc*/

<?php

        $vco_server = "10.1.1.1"; //your vco ip

        $vco_user = "administrator";

        $vco_pass = "secret";

?>

/*findworkflow.php*/

<?php

        include ("parameters.inc");

        $vco = new SoapClient('https://' . $vco_server . ':8281/vmware-vmo-webcontrol/webservice?WSDL');

        $param = array(username=>$vco_user,password=>$vco_pass);

        $result = $vco->getAllWorkflows($param);

        foreach ($result as $item)

        {

                foreach ($item as $work)

                {

                        echo $work->name;

                        echo "<br>";

                        echo "ID=";

                        echo $work->id;

                        echo "<br>";

                        echo "$work->description";

                        echo "<br>";

                        echo "<br>";

                }

        }

?>

If error still persists, please open the your web server log, if you running into linux using apache search at /var/log/apache2/error.log and

If you wanna execute the workflow based on workflow id just use executeWorkflow() and please refer to VCO web services guide....

Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

Ilian,

Thanks a ton!! your code works like a charm Smiley Happy

I am trying to figure out how to execute a workflow, but in vain.

Can you give me a clue on what parameters need to be passed for starting a workflow execution.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Please have a look at this : How to use the REST API to Start a Workflow

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

The REST client is not working for me.

GET method is itself not working. Not sure what I missed.

REST_GET.PNG

Reply
0 Kudos
Andreas_Diemer
Enthusiast
Enthusiast
Jump to solution

If you are using vCO5.5 or higher use https://server:8281/vco/api/....

The docu is outdated for this URLs

------ for correct and / or useful answers please award points visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com
Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

We do have vco5.5 installed.

Is there any other documentation available for this?

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

online doc is available for the REST API https://vcoserver:8281/vco/api

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
Andreas_Diemer
Enthusiast
Enthusiast
Jump to solution

TYPO ... 😉 online doc is available for the REST API https://vcoserver:8281/vco/api/docs

------ for correct and / or useful answers please award points visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Tx Andreas. I need to get another coffe

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

Hi,

I am now able to execute workflows through REST-client

I am trying the same with the following php code using CURL but the HTTP code is '0'

Can you please point out what I am missing.

<?php

$service_url = 'https://vcoserver:8281/vco/api/workflows/719f3902-6628-469a-a8fe-ed68501d961e/executions/';

//echo $service_url;

try

{

       $curl = curl_init($service_url);

//      $curl_post_data_xml=new SimpleXMLElement('<execution-context xmlns="http://www.vmware.com/vco"><parameters></parameters></execution-context>');

        $curl_post_data_xml='<execution-context xmlns="http://www.vmware.com/vco"><parameters></parameters></execution-context>';

        curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"POST");

        curl_setopt($curl,CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/xml'));

        curl_setopt($curl,CURLOPT_USERPWD,"username:password");

        curl_setopt($curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

       curl_setopt($curl, CURLOPT_POST, 1);

       curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data_xml);

       $curl_response = curl_exec($curl);

        $code = curl_getinfo($curl,CURLINFO_HTTP_CODE);

        echo $code;

        curl_close($curl);

}

catch(Exception $ec)

{

        echo $ec;

}

?>

iiliev
VMware Employee
VMware Employee
Jump to solution

Could you use

print curl_error($curl);

after curl_exec to check if there are some errors?

If there is some SSL certificate error, like 'SSL certificate problem: unable to get local issuer certificate', you can either install root certificates (Google for information how to do so), or disable verification of peer certificates in CURL with something like:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

Reply
0 Kudos
deepthy
Enthusiast
Enthusiast
Jump to solution

Thanks a ton !

It worked.

Reply
0 Kudos