Question

For those of you who aren't familiar with MindBody ( http://www.mindbodyonline.com ) it is a convenient merchant processing tool for health and wellness centres like the yoga studio I do work for. It can track clients and manage employees and all sorts of great stuff. I have been generating reports using nuSOAP and the MindBody SOAP API v0.4 for a while now. When my client asked me to generate a report that needed the updated MindBody SOAP API v0.5 I decided to drop nuSOAP for PHP5's native SOAP. Then I heard that Zend Soap offers the same speed as the native soap but also has a bunch of other benefits so I wrote the following code.

<?php
require_once 'Zend/Soap/Client.php';
$sourceCredentials = array('SourceName'=>'****', 'Password'=>"****", 'SiteIDs'=>array('****'));

try {
  $client = new Zend_Soap_Client('https://api.mindbodyonline.com/0_5/ClientService.asmx?WSDL');
  $result = $client->GetClients(array("SourceCredentials"=>$sourceCredentials, "XMLDetail"=>"Basic", "PageSize"=>"10", "CurrentPageIndex"=>"0", "ClientIDs"=>array("100009536")));
  echo $client->getLastRequest();

} catch (SoapFault $s) {
  die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
} catch (Exception $e) {
  die('ERROR: ' . $e->getMessage());
}
var_dump($client);
var_dump($result);
?>

I'm not sure what I'm doing wrong. The page just keeps loading and loading but never loads. I'm hoping someone can take a look at the WSDL or the API Docs and tell me what I'm missing. Here's the link to the API Docs http://api.mindbodyonline.com/Doc I am trying to use the client service in this example.

If I comment out the $result = $client->GetClients~ line then the page loads and the var_dump of $client returns this

object(Zend_Soap_Client)#1 (28) { ["_encoding:protected"]=> string(5) "UTF-8" ["_classmap:protected"]=> NULL ["_faultExceptions:protected"]=> array(0) { } ["_soapVersion:protected"]=> int(2) ["_uri:protected"]=> NULL ["_location:protected"]=> NULL ["_style:protected"]=> NULL ["_use:protected"]=> NULL ["_login:protected"]=> NULL ["_password:protected"]=> NULL ["_proxy_host:protected"]=> NULL ["_proxy_port:protected"]=> NULL ["_proxy_login:protected"]=> NULL ["_proxy_password:protected"]=> NULL ["_local_cert:protected"]=> NULL ["_passphrase:protected"]=> NULL ["_compression:protected"]=> NULL ["_connection_timeout:protected"]=> NULL ["_stream_context:protected"]=> NULL ["_features:protected"]=> NULL ["_cache_wsdl:protected"]=> NULL ["_user_agent:protected"]=> NULL ["_wsdl:protected"]=> string(58) "https://api.mindbodyonline.com/0_5/ClientService.asmx?WSDL" ["_soapClient:protected"]=> NULL ["_lastMethod:protected"]=> string(0) "" ["_soapInputHeaders:protected"]=> array(0) { } ["_permanentSoapInputHeaders:protected"]=> array(0) { } ["_soapOutputHeaders:protected"]=> array(0) { } }

I'm not sure what the values should be but all those NULLs look bad to me. I have tried different combinations of nesting the arrays passed to $client->GetClients and I've tried accessing different functions other than GetClients as well..

Était-ce utile?

La solution

Okay so for anyone who happens to google this and wants the answer. You have to add a user-agent string to your page headers in order to make it work with the API for some reason. Add this code to the top of your PHP page

ini_set("user_agent", "FOOBAR");

then you need to create a Zend_Soap_Client with soap_version set to SOAP_1_1. Create an array of the parameters you are going to send. Then call the function you want and in this case you pass in a array ( "Reqest"=>$params )

$client = new Zend_Soap_Client('https://api.mindbodyonline.com/0_5/ClientService.asmx?WSDL', array("soap_version"=>SOAP_1_1));
$sourceCredentials = array('SourceName'=>'****', 'Password'=>"****", 'SiteIDs'=>array('****'));
$params = array("SourceCredentials"=>$sourceCredentials, "XMLDetail"=>"Basic", "PageSize"=>"10", "CurrentPageIndex"=>"0", "ClientIDs"=>array("123456789","123456789"));
$result = $client->GetClients(array("Request"=>$params));

EDIT: For more information check out the article I'm writing on how to get started with the MINDBODY API in under 30 minutes

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top