I am doing a PHP SOAP Request as follows (my code, location removed as I'm not allow to publish)
try {
$location = "http://myUrltoWSDLhere";
$client = new SoapClient($location,
array(
'soap_version' => SOAP_1_1,
'login' => 'myuser',
'password' => 'mypass'
));
$params = array(array('BUKRS'=> 1));
$x = $client->ZIbFtiWsCredPosToWeb( $params );
print_r($x);
} catch (Exception $e) {
echo $e->getMessage();
}
I've been trying countless combinations how to pass the params to my method and I am doing a print_r($x) and gives me the below output.
stdClass Object ( [EBkpf] => stdClass Object ( ) [EMsgnr] => 6 [EMsgtxt] => BUKRS is missing [EMsgtyp] => E [ESstMon] => 00000000000000000000 )
Important: SoapClient getTypes returns the following for this method and the IBukrs is the field I am trying to pass data to. In SAP the Company Code is "BUKRS" so I had tried BUKRS and IBukrs and also Bukrs.
Any help would be greatly appreciated!!
[43] => struct ZIbFtiWsCredPosToWeb {
int IAnz;
char1 IAp;
char4 IBukrs;
ZibSstGjahr IGjahr;
ZibSstCredTt IKreditor;
char1 IOp;
numeric20 ISstMon;
}
WSDL Content: http://pastebin.com/fU5PhD9B
Related
I've had some difficulty finding resources on this, to connect to a SOAP API using PHP and easily attach the array results to variables for display purposes.
Here is the SOAP API XML of GetCostCenters function within the API:
<Response><Status><Result>1</Result><Description>OK</Description></Status><CostCenters><CostCenter><ID>4</ID><Branch>Adelaide</Branch></CostCenter><CostCenter><ID>6</ID><Branch>Derby</Branch></CostCenter><CostCenter><ID>33</ID><Branch>GT Perth</Branch></CostCenter><CostCenter><ID>7</ID><Branch>Hobart Branch</Branch></CostCenter><CostCenter><ID>46</ID><Branch>Lawns & Maintenance</Branch></CostCenter><CostCenter><ID>10</ID><Branch>London</Branch></CostCenter><CostCenter><ID>3</ID><Branch>Melbourne</Branch></CostCenter><CostCenter><ID>45</ID><Branch>NECA Apprentices</Branch></CostCenter><CostCenter><ID>17</ID><Branch>New York</Branch></CostCenter><CostCenter><ID>48</ID><Branch>Nursing NSW</Branch></CostCenter><CostCenter><ID>1</ID><Branch>Perth</Branch></CostCenter><CostCenter><ID>44</ID><Branch>Registration</Branch></CostCenter><CostCenter><ID>16</ID><Branch>Rio</Branch></CostCenter><CostCenter><ID>50</ID><Branch>Subiaco</Branch></CostCenter><CostCenter><ID>51</ID><Branch>Subiaco</Branch></CostCenter><CostCenter><ID>2</ID><Branch>Sydney</Branch></CostCenter><CostCenter><ID>42</ID><Branch>test - tester</Branch></CostCenter><CostCenter><ID>49</ID><Branch>TesterOM</Branch></CostCenter><CostCenter><ID>8</ID><Branch>Tom Price</Branch></CostCenter><CostCenter><ID>47</ID><Branch>Traffic Control NSW</Branch></CostCenter></CostCenters></Response>
Here is my PHP:
$client = new SoapClient("https://api.myfeed.com/feed.asmx?WSDL", array(
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true
));
// GET RESULTS
$result = $client->GetCostCenters(array(
'CompanyID' => 'MYID',
'APIKey' => 'MYKEY',
'APIPassword' => 'MYPASS',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true
));
echo '<pre>';
print_r($result);
echo '</pre>';
Outputs it all on one line in [any] like this:
stdClass Object
(
[GetCostCentersResult] => stdClass Object
(
[any] => 1OK4Adelaide6Derby33GT Perth7Hobart Branch46Lawns & Maintenance10London3Melbourne45NECA Apprentices17New York48Nursing NSW1Perth44Registration16Rio50Subiaco51Subiaco2Sydney42test - tester49TesterOM8Tom Price47Traffic Control NSW
)
)
and I can't figure out why, ideally I want it as an array so I can assign variables and run a loop to display the information.
Any ideas? Thanks in advance.
Convert the result from string to xml object (simplexml_load_string):
$resultAsXml = simplexml_load_string($result);
Then convert the object to array using the json encoding (json_encode, json_decode):
$resultAsArray = json_decode(json_encode($resultAsXml), true);
Note the second argument passed to json_decode:
When true, JSON objects will be returned as associative arrays;
In your case:
$client = new SoapClient("https://api.myfeed.com/feed.asmx?WSDL", array(
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true
));
// GET RESULTS
$result = $client->GetCostCenters(array(
'CompanyID' => 'MYID',
'APIKey' => 'MYKEY',
'APIPassword' => 'MYPASS',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true
));
$resultAsXml = simplexml_load_string($result);
$resultAsArray = json_decode(json_encode($resultAsXml), true);
echo '<pre>';
print_r($resultAsArray);
echo '</pre>';
Since Soap errors are WSDL specific I'm asking this question. I'm trying to add a relation in an online accountancy application. Authenticating and getting works just fine.
This is the code I'm using (Security code and SessionID are working fine when Getting relations):
$params = array( "input" => array( "SecurityCode2" => $SecurityCode2,
"SessionID" => $SessionID,
"cRelatie" => array(
"ID" => NULL,
"AddDatum" => date("Y-m-d h:i:s"),
"Code" => "PUBID".sprintf('%04d', $vve['id']),
"Bedrijf" => $Bedrijf,
"Contactpersoon" => $Contactpersoon
)
)
);
try {
$response = $client->__soapCall("AddRelatie", $params);
}
catch (Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
I've also tried nesting the cRelatie within an array with one index called oRel (see WSDL), but that didn't work either.
Error:
Caught exception: Server was unable to process request. ---> Object reference not set to an instance of an object.
This is the WSDL location
https://soap.e-boekhouden.nl/soap.asmx?wsdl
Got it working:
There where non documented required fields
And date wasn't allowed to have time, In contrary to the WSDL
$params = array( "input" => array(
"SecurityCode2" => $SecurityCode2,
"SessionID" => $SessionID,
"oRel" => array(
"ID" => 0,
"Gb_ID" => 0,
"GeenEmail" => 0,
"NieuwsbriefgroepenCount" => 0,
"AddDatum" => date("Y-m-d"),
"Code" => "PUBID".sprintf('%04d', $vve['id']),
"Bedrijf" => $Bedrijf,
"Contactpersoon" => $Contactpersoon
)
));
I am trying to retrieve the error message that comes with a GuzzleHttp\Exception\ConnectException in Guzzle 6.
I read that in older version this could be achieved with getResponse().
However, the method now returns null by default.
This is my code:
$responses = Pool::batch($client, $requests($this->list), array(
'concurrency' => 15,
));
foreach ($responses as $event) {
$classname = get_class($event);
$raw = print_r($event,1);
if ($classname == "GuzzleHttp\Exception\ConnectException") {
$response = json_encode((string)$event->getResponse());
}
echo $response;
}
$response is empty.
However, $raw contains these lines:
[0] => GuzzleHttp\Exception\ConnectException Object
(
[request:GuzzleHttp\Exception\RequestException:private] => GuzzleHttp\Psr7\Request Object
(
[method:GuzzleHttp\Psr7\Request:private] => GET
....
)
[response:GuzzleHttp\Exception\RequestException:private] =>
[handlerContext:GuzzleHttp\Exception\RequestException:private] => Array
(
[errno] => 6
[error] => Could not resolve host: mydomain.it
[url] => http://mydomain.it/
[content_type] =>
[http_code] => 0
....
How do I retrieve the "Could not resolve host: mydomain.it" message?
All I found was "you need to catch the error". But how when I am using Pool::batch and everything already is in my responses array?
Use $event->getMessage() (Exception Message) instead of $event->getResponse() because there is no connection, so no response
I have an ecommerce website which is under development right now. I bought a web software. I want to connect to the webservice and add some brands.
This is my webservice WSDL url: http://www.cantabu.com/Servis/UrunServis.svc?wsdl
The method for adding a new brand is "SaveMarka".
This is my initial code:
ini_set("soap.wsdl_cache_enabled", "0");
$wsdl = "http://www.cantabu.com/Servis/UrunServis.svc?wsdl";
$authCode = "MY_WEBSERVICE_AUTHENTICATION_CODE";
$client = new SoapClient($wsdl);
When i print_r $client->__getFunctions() The result is (Related to SaveMarka method):
Array
(
[4] => SaveMarkaResponse SaveMarka(SaveMarka $parameters)
)
And when i print_r $client->__getTypes(), the result is (Up to 5th index of the result array, because others are unrelated to SaveMarka):
Array
(
[0] => struct ArrayOfint {
int int;
}
[1] => struct ArrayOfstring {
string string;
}
[2] => struct ArrayOfKategori {
Kategori Kategori;
}
[3] => struct Kategori {
boolean Aktif;
int ID;
string Icerik;
string Kod;
int PID;
string SeoAnahtarKelime;
string SeoSayfaAciklama;
string SeoSayfaBaslik;
int Sira;
string Tanim;
}
[4] => struct ArrayOfMarka {
Marka Marka;
}
[5] => struct Marka {
boolean Aktif;
int ID;
string SeoAnahtarKelime;
string SeoSayfaAciklama;
string SeoSayfaBaslik;
string Tanim;
}
In their web service document, they say; if you want to add a new brand, the ID should be 0 (zero). Otherwise, whe webservice will update the brand related to that ID.
I have tried different variations of SaveMarka method. But they all failed with varied results.
First of all, i have created a Marka class.
class Marka{
var $ID;
var $SeoAnahtarKelime;
var $SeoSayfaBaslik;
var $SeoSayfaAciklama;
var $Tanim;
var $Aktif;
function __construct($id, $seo, $seoAciklama, $seoBaslik, $ad){
$this->ID = $id;
$this->SeoAnahtarKelime = $seo;
$this->SeoSayfaBaslik = $seoBaslik;
$this->SeoSayfaAciklama = $seoAciklama;
$this->Tanim = $ad;
$this->Aktif = true;
}
}
Then i have tried to do this:
$marka = new Marka(0, "pg", "P&G", "P&G", "P&G");
$newMarka = array(
"UyeKodu" => $authCode",
"Marka" => $marka
);
$client->__soapCall("SaveMarka", $newMarka);
The result is:
Type: SoapFault
Message: The formatter threw an exception while trying to deserialize
the message: Error in deserializing body of request message for
operation 'SaveMarka'. End element 'Body' from namespace
'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element
'param1' from namespace ''. Line 2, position 150.
I also tried (I don't know why):
$marka = new Marka(0, "pg", "P&G", "P&G", "P&G");
$newMarka = array(array(
"UyeKodu" => $authCode",
"Marka" => $marka
));
$client->__soapCall("SaveMarka", $newMarka);
And the result is:
Type: SoapFault
Message: Object reference not set to an instance of an object.
Then i get rid of the Marka class and tried to do it simpler without using a class:
$newMarka = array(
"UyeKodu" => $authCode,
"ID" => 0,
"Tanim" => "P&G",
"Aktif" => true,
"SeoAnahtarKelime" => "pg",
"SeoSayfaBaslik" => "P&G",
"SeoSayfaAciklama" => "P&G"
);
$client->__soapCall("SaveMarka", $newMarka);
Result is:
Type: SoapFault
Message: The formatter threw an exception while trying to deserialize
the message: Error in deserializing body of request message for
operation 'SaveMarka'. End element 'Body' from namespace
'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element
'param1' from namespace ''. Line 2, position 150.
And also (again, i don't know why)
$newMarka = array(array(
"UyeKodu" => $authCode,
"ID" => 0,
"Tanim" => "P&G",
"Aktif" => true,
"SeoAnahtarKelime" => "pg",
"SeoSayfaBaslik" => "P&G",
"SeoSayfaAciklama" => "P&G"
));
$client->__soapCall("SaveMarka", $newMarka);
And the result is:
Type: SoapFault
Message: Object reference not set to an instance of an object.
What am i doing wrong?
Can anyone please help me with adding a new brand? I have supplied the functions, types, wsdl link and all my tries.
Please, help.
Let me set the scene:
I'm a PHP developer that needs to take info from a web form and send it into a clients Salesforce. At first I though it was as simple as using Web2Lead. However the client has a Salesforce developer in house.
The in house developer has sent me partner.wsdl and CatalystWebservice.wsdl files along with login details to their sandbox to run all this on. The in house developer has basically said I need to use the SOAP API of Salesforce and once connected and logged in I need to call ->makeContact("FormField1", "FormField2", "etc...");
So after spending all day trying many things and hitting many problems I have finally hit a wall I cannot climb. Here is my PHP code I have now:
<pre>
<?php
define("SOAP_CLIENT_BASEDIR", "../soapclient");
$USERNAME = '******#********' ;
$PASSWORD = '******************************' ;
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner2.wsdl.xml');
$loginResult = $mySforceConnection->login($USERNAME, $PASSWORD);
$location = $mySforceConnection->getLocation();
$session_ID = $mySforceConnection->getSessionId();
$client = new SoapClient(SOAP_CLIENT_BASEDIR.'/CatalystWebservice.wsdl.xml');
$sforce_header = new SoapHeader("http://soap.sforce.com/schemas/class/CatalystWebservice", "SessionHeader", array( "sessionId" => $session_ID ) );
$client->__setSoapHeaders( array( $sforce_header ) );
$client->makeContact("*****", "*****", "Address1", "Address2", "London", "****", "no-one#****", "0123456789", "07891236456", "New Build Homebuy", "This is my question\n\nAnd an other line", "1", "Test");
} catch (Exception $e) {
print_r($e);
}
?>
</pre>
I have starred out sensitive information for here. When I run the above code I get the following output:
SoapFault Object
(
[message:protected] => UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: ***********-*** (***********)
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/******/public_html/********/test/partner.php
[line:protected] => 23
[trace:Exception:private] => Array
(
[0] => Array
.....
And the CatalystWebservice.wsdl.xml file
The in house developer has developed something in C# to test his WebService and it works perfectly fine so it must be something I am not doing right. What am I doing incorrectly?
I found the solution... I had to make sure I was sending the data as an associative array like so:
$response = $client->makeContact
(
array
(
"sLastName" => (string) $wpcf7_data->posted_data['last-name'],
"sFirstName" => (string) $wpcf7_data->posted_data['first-name'],
"sAddress1" => (string) $wpcf7_data->posted_data['address-one'],
"sAddress2" => (string) $wpcf7_data->posted_data['address-two'],
"sCity" => (string) $wpcf7_data->posted_data['town-city'],
"sPostcode" => (string) $wpcf7_data->posted_data['post-code'],
"sEmail" => (string) $wpcf7_data->posted_data['email-address'],
"sPhone" => (string) $wpcf7_data->posted_data['telephone'],
"sMobile" => (string) "",
"sEnquiries" => (string) $wpcf7_data->posted_data['enquiry'],
"sComment" => (string) $wpcf7_data->posted_data['comments'],
"sPropertyID" => (string) wpcf7_special_mail_tag_for_post_data( "", "_post_id" ),
"sPropertyName" => (string) wpcf7_special_mail_tag_for_post_data( "", "_post_title" ),
)
);