I am trying to write a snippet of PHP to connect to a third party's API via SOAP to enter some data into their database. The API requires me to pass several mandatory fields for every call (username, password, companyid, entitytype) in addition to the mandatory data fields. It also requires me to call the "ValidateEntity" funciton before calling the "CreateEntity" function. Documentation can be found here:
http://wiki.agemni.com/Getting_Started/APIs/Database_API
I have never worked with SOAP before, so I am very new to this. Here is what I have so far:
error_reporting(E_ALL);
ini_set('display_errors', '1');
$client = new SoapClient("http://agemni.com/AgemniWebservices/service1.asmx?WSDL", array('trace'=> true));
$options = array(
'username' => "myuser",
'password' => "mypassword",
'companyid' => myID,
'entitytype' => 2
);
$params = array(
'fname' => "John",
'lname' => "Doe",
'phone' => "859-333-3333",
'zip' => "40332",
'area id' => "12345",
'lead id' => "28222",
'contactdate' => "4/10/2010"
);
$validate = $client->__soapCall("ValidateEntity", array($params), array($options));
$create = $client->__soapCall("CreateEntity", array($params), array($options));
echo "<pre>";
var_dump($client-> __getLastRequestHeaders());
var_dump($client-> __getLastRequest());
var_dump($client-> __getLastResponseHeaders());
var_dump($client-> __getLastResponse());
var_dump($result);
echo "</pre>";
Upon executing this code, I get the following error:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'objecttype' property in /www/tmp/index-soap.php:24 Stack trace: #0 /www/tmp/index-soap.php(24): SoapClient->__soapCall('ValidateEntity', Array) #1 {main} thrown in /www/stealth/tmp/index-soap.php on line 24
I guess my question is.. am I even going about doing this the right way? I know this is a very broad question, but I appreciate any advice you can give me about making this work. Please let me know if you require more detail.
Thanks!
UPDATE:
Ok, so I got a little bit further. I changed:
$validate = $client->__soapCall("ValidateEntity", array($params), array($options));
to:
$validate = $client->__soapCall("ValidateEntity", $params, $options);
This resulted in the following ouput:
NULL
NULL
NULL
NULL
object(stdClass)#2 (1) {
["ValidateEntityResult"]=>
object(SoapVar)#4 (4) {
["enc_type"]=>
int(0)
["enc_value"]=>
object(stdClass)#3 (10) {
["statusCode"]=>
string(24) "CompanyNameNotIdentified"
["status"]=>
string(5) "Error"
["description"]=>
string(37) "Company name could not be identified."
["errorNumber"]=>
int(1)
["xmlResult"]=>
string(39) ""
["EntityValidated"]=>
bool(false)
["EntityCreated"]=>
bool(false)
["EntityUpdated"]=>
bool(false)
["EntityIDCreated"]=>
int(0)
["isloggedIn"]=>
bool(false)
}
["enc_stype"]=>
string(15) "ExceptionReport"
["enc_ns"]=>
string(44) "http://tempuri.org/AgemniWebService/Service1"
}
}
So, it seems like $option is not getting passed, because the server is telling me that the companyID is not set.
Ideas?