Salesforce php toolkit 20.0 create not working - php

Im using salesforce PHP Toolkit 20.0
Here is my code, pretty simple:
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection(TEMPLATEPATH."/admin/salesforce/enterprise_wsdl.xml");
$login = $mySforceConnection->login($username, $password.$securityToken);
$sObject = new stdclass();
$sObject->First_Name__c = 'aaaa';
$sObject->Last_Name__c = 'vvvvv';
$sObject->Email__c = 'test#gmail.com';
$createResponse = $mySforceConnection->create(array($sObject), 'Patient__c');
This is the soap error im getting
INVALID_TYPE: Must send a concrete entity type
I think that there is a problem with the soap request (the xml is empty)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:enterprise.soap.sforce.com"><SOAP-ENV:Header><ns1:SessionHeader><ns1:sessionId>xxxxxxx</ns1:sessionId></ns1:SessionHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:create><ns1:sObjects/></ns1:create></SOAP-ENV:Body></SOAP-ENV:Envelope>
I think that this is how the Request should look like
Has anyone encountered such a problem ?

It turns out that the toolkit 20.0 is not supported on PHP7

Related

How to retrieve metadata from salesforce with force.com toolkit for PHP?

I want to retrieve the value of a parameter from my salesforce instance. For example, I want to recover the trusted IP range:
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_securitysettings.htm
To do this, use the Metadata API. To access to this API, I use the force.com toolkit for PHP.
However, the examples given only deal with the creation or the update of the parameters:
https://developer.salesforce.com/blogs/developer-relations/2011/11/extending-the-force-com-toolkit-for-php-to-handle-the-metadata-api.html
How to simply get the value of the parameter (for example the trusted IP range)?
The PHP toolkit shipped by Salesforce is quite outdated and should not be used. There are more recent forks/community projects (one,two) that attempt to implement a modern PHP client, perhaps one of these will work for you.
A simple(r) solution is to retrieve the SecuritySettings via a plain SOAP call to the Metadata API. The request payload with API version set to 46.0 should be
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Security</members>
<name>Settings</name>
</types>
<version>46.0</version>
</Package>
and the response looks like this (only relevant portion is shown, the actual response is much larger)
<?xml version="1.0" encoding="UTF-8"?>
<SecuritySettings xmlns="http://soap.sforce.com/2006/04/metadata">
<networkAccess>
<ipRanges>
<description>...</description>
<end>1.255.255.255</end>
<start>0.0.0.0</start>
</ipRanges>
</networkAccess>
</SecuritySettings>
Translating to PHP:
$wsdl = PUBLIC_PATH . '/wsdl-metadata.xml';
$apiVersion = 46.0;
$singlePackage = true;
$members = 'Security';
$name = 'Settings';
$params = new StdClass();
$params->retrieveRequest = new StdClass();
$params->retrieveRequest->apiVersion = $apiVersion;
$params->retrieveRequest->singlePackage = $singlePackage;
$params->retrieveRequest->unpackaged = new StdClass();
$params->retrieveRequest->unpackaged->version = $apiVersion;
$params->retrieveRequest->unpackaged->type = new stdClass();
$params->retrieveRequest->unpackaged->type->members = $members;
$params->retrieveRequest->unpackaged->type->name = $name;
$option = [
'trace' => TRUE,
];
// Namespaces
$namespace = 'http://soap.sforce.com/2006/04/metadata';
$client = new SoapClient($wsdl, $option);
$header = new SoapHeader($namespace, "SessionHeader", array ('sessionId' => $token)); // NEED: access token
$client->__setSoapHeaders($header);
$client->__setLocation($serverUrl); // NEED: service endpoint URL
$serviceResult = $client->retrieve($params);
You'll need to provide an access token ($token) and a service endpoint ($serverUrl).
For anyone trying to get this to work, identigral's example didn't work for me, had to do the following:
change $client->setEndpoint($serverUrl); to $client->__setLocation($serverUrl);
I was using Oauth to login, so you'll need to construct the $serverUrl from the response:
<instance_url> + '/services/Soap/m/46.0/' + <org id (from id)>
Example:
'https://your-production-or-sandbox-name.my.salesforce.com/services/Soap/m/46.0/your-org-id'

SOAP-ERROR: Encoding: object has no 'checkConnectivityRequest' property

I am using the COLT (ISP) WSDL in PHP (Laravel), I have created all the objects using WSDL2PHPGENERATOR, and imported these into my project.
The XML which works via SOAPUI is the following:
<soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v5="http://www.colt.net/xml/ns/b2bFramework/v5" xmlns:con="http://aat.colt.com/connectivityservice">
<soapenv:Header/>
<soapenv:Body>
<v5:checkConnectivity>
<checkConnectivityRequest>
<con:checkConnectivityRequest con:schemaVersion="5.0">
<con:requestType>ALL</con:requestType>
<con:requestMode>
<con:requestID>123</con:requestID>
<con:siteAddress>
<con:premisesNumber>16</con:premisesNumber>
<con:streetName>Rue Friant</con:streetName>
<con:cityTown>Paris</con:cityTown>
<con:postalZipCode>75014</con:postalZipCode>
<con:coltOperatingCountry>France</con:coltOperatingCountry>
<con:requiredProduct>Colt Voice Line (v)</con:requiredProduct>
<con:isConvergedVL>false</con:isConvergedVL>
<con:connectivityType>ALL</con:connectivityType>
</con:siteAddress>
</con:requestMode>
</con:checkConnectivityRequest>
</checkConnectivityRequest>
</v5:checkConnectivity>
</soapenv:Body>
</soapenv:Envelope>
My PHP Code is the following:
$request_id = 1123123;
$Connectivity_Type = \App\Classes\WSDLs\COLT\Connectivity_Type::COLTFibre;
$LocationAddress_Type = new \App\Classes\WSDLs\COLT\LocationAddress_Type(array($Connectivity_Type));
$LocationAddress_Type->PremisesNumber = 1;
$LocationAddress_Type->StreetName = "Whittington Avenue";
$LocationAddress_Type->CityTown = "London";
$LocationAddress_Type->PostalZipCode = "EC3V 1PJ";
$LocationAddress_Type->ColtOperatingCountry = \App\Classes\WSDLs\COLT\coltOperatingCountry::UnitedKingdom;
$LocationAddress_Type->RequiredProduct = \App\Classes\WSDLs\COLT\RequiredProduct_Type::ColtIPAccess;
$requestMode = new \App\Classes\WSDLs\COLT\RequestMode_Type($request_id, array($LocationAddress_Type));
$Request_Type = \App\Classes\WSDLs\COLT\Request_Type::SITE;
$schemaVersion = 5.0;
$checkConnectivityRequest = new \App\Classes\WSDLs\COLT\checkConnectivityRequest($Request_Type, $requestMode, $schemaVersion);
$checkConnectivity = new \App\Classes\WSDLs\COLT\checkConnectivity();
$checkConnectivity->setCheckConnectivityRequest($checkConnectivityRequest);
Log::info(array($checkConnectivity));
//return "Check Log";
try{
$a = new \App\Classes\WSDLs\COLT\ColtB2bFrameworkcommonwebSvcProviderb2bFramework_v5(array(
"exceptions" => 0,
"trace" => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'login' => config('mike.COLT_API_USERNAME'),
'password' => config('mike.COLT_API_PASSWORD'),
));
//return var_dump($a->__getTypes());
$response = $a->checkConnectivity($checkConnectivity);
However when getting this working it comes back with the error:
SOAP-ERROR: Encoding: object has no 'checkConnectivityRequest'
property
It won't even show last request etc in order to debug.
I wonder whether it is something do do with the XML having two
Layers.
Have I missed something?
Thanks in advance,
Mike
For anyone who runs across this in future. I updated to a newer version of their WSDL, and it started working, it was clearly an error in that.
However not so much that it didnt work in SOAPUI.
If you encounter this. It may be worth just querying the Data Directly rather than using a soap client in PHP.

Headers for connecting to a SOAP webservice using PHP

I am trying to connect to a SOAP webservice using php. I am very new to using php.
I can connect to the service, the test below returns a list of all the available functions of the webservice.
$url = "http://...client_ip.../dkServiceDefault/dkWSItemsCGI.exe/wsdl/IItemService";
$client = new SoapClient($url);
var_dump($client->__getFunctions());
If I try to access one of these functions(ex. NumberOfModifiedItems) then I get an error stating that I need to supply a SOAP header with a username and password.
According to the documentation of the SOAP service the header needs to look like this:
<soap:Header>
<q1:BasicSecurity id="h_id1" xmlns:q1="urn:dkWSValueObjects">
<Username xsi:type="xsd:string">username</Username>
<Password xsi:type="xsd:string">password</Password>
</q1:BasicSecurity>
</soap:Header>
How can I make this header in php? How do I attach it to the SoapClient? I have a username and password but I can't figure out how to create the exact header to send to the webservice. I have tried following several tutorials, but I just can't seem to get it to work.
You may pass SOAP headers with SoapHeader class and SoapClient::__setSoapHeaders method:
<?php
$url = "http://...client_ip.../dkServiceDefault/dkWSItemsCGI.exe/wsdl/IItemService";
$client = new SoapClient($url);
$namespace = "urn:dkWSValueObjects";
$authentication = array(
'Username' => 'yourname',
'Password' => 'yourpassword'
);
$header = new SoapHeader($namespace, 'BasicSecurity', $authentication, false);
$client->__setSoapHeaders($header);
var_dump($client->__getFunctions());
?>

PHP Soap client with complex types

I am trying to get request with this structure:
<SOAP-ENV:Body>
<ns1:getCreditReportTypes>
<reportTypeRequest>
<reportParams xsi:type="ns1:personCreditReportParams">
<personId>4</personId>
<consentConfirmed>true</consentConfirmed>
</reportParams>
</reportTypeRequest>
</ns1:getCreditReportTypes>
</SOAP-ENV:Body>
Here is my php-code:
$obj = new \stdClass();
$obj->personId = 4;
$obj->consentConfirmed = true;
$data = new \SoapVar($obj, SOAP_ENC_OBJECT, "personCreditReportParams", $namespace, "reportParams");
$res = $this->client->getCreditReportTypes(new \SoapParam($data,"reportTypeRequest"));
However, php generates invalid xml:
<SOAP-ENV:Body>
<ns1:getCreditReportTypes xsi:type="ns1:personCreditReportParams">
<consentConfirmed>true</consentConfirmed>
<personId>4</personId>
</ns1:getCreditReportTypes>
</SOAP-ENV:Body>
How can I make a valid XML with object-way?
You should definitively use a WSDL to php generator such as PackageGenerator.
It'll ease you the request construction, the response handling.
For those who'll get the same problem.
My solution is to use nusoap (https://github.com/yaim/nusoap-php7). This library allows you to make complicated requests, including SWA (SOAP with Attachments).
Here is working code for my question:
$person = array("personId"=>$id, "consentConfirmed"=>$confirmed);
$data = array(
"reportParams"=>new soapval("reportParams", "personCreditReportParams", $person, false, $namespace)
);
$result = $client->call("getCreditReportTypes", $data, $namespace);
P.S. I've tried some generators and no one could make correct request, although classes were generated correctly.

WSO2 WSF PHP SOAP XML request payload format

I have set-up wso2 PHP WS 2.1.0 framework on a centos server (PHP 5.2.10, apache/2.2.3) with the native PHP SOAP extension active. The sample WS clients work fine. The only difference in my WS installation to the default is that the wsf files are in the path structure /usr/lib64/php/modules/wsf_c/ instead of /var/lib/.
I am having trouble generating a complete SOAP request using the following client script -
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$reqPayloadString = <<<XML
<soap:Envelope xmlns:soap=”http://www.w3.org/2003/05/soap-envelope” xmlns:typ=”http://service.dataxmldistribution.argos.cls.fr/types”>
<soap:Header/>
<soap:Body>
<typ:xmlRequest>
<typ:username>user</typ:username>
<typ:password>password</typ:password>
<typ:platformId>'1,2,3,4,5'</typ:platformId>
<typ:nbDaysFromNow>10</typ:nbDaysFromNow>
</typ:xmlRequest>
</soap:Body>
</soap:Envelope>
XML;
$reqMessage = new WSMessage($reqPayloadString);
try {
$client = new WSClient(array(
"wsdl" => "http://ws-argos.cls.fr/argosDws/services/DixService?wsdl",
"to" => "http://ws-argos.cls.fr/argosDws/services/DixService",
"useSOAP" => 1.2,
"action"=>"getXml"
));
$resMessage = $client->request($reqPayloadString);
printf("Response = %s <br/>\n", htmlspecialchars($resMessage->str));
} catch (Exception $e) {
if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->code);
} else {
printf("Message = %s\n",$e->getMessage());
}
}
printf("<br/> Request = %s </br>",
htmlspecialchars($client->getLastRequest()));
printf("<br/> Response = %s </br>",
htmlspecialchars($client->getLastResponse()));
?>
The script returns the following -
Message = Invalid Input Message
Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope>
Response = <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="en">Fault occurred while processing.</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>
The client log shows one error - 'om_document.c(102) Unable to get root node'.
I assume that the fact that the xml request is missing from within the body element in the print-out from getLastRequest that I need to format the payload xml differently - possibly with namespaces?
I am unsure how this should look, so would be extremely gratefully of any advice, if this is the issue. I have tried this request with and without the 'wsdl' referenced in the WSClient array, and tried defining the payload as an array instead of an XML string (as you might with a native SOAP request).
Thank you, William

Categories