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.
Related
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'
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.
I need to send the following SOAP request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://touricoholidays.com/WSDestinations/2008/08/DataContracts">
<soapenv:Header>
<dat:LoginHeader>
<dat:username>myUserName</dat:username>
<dat:password>myPassword</dat:password>
<dat:culture>en_US</dat:culture>
<dat:version>8</dat:version>
</dat:LoginHeader>
</soapenv:Header>
<soapenv:Body>
<dat:GetDestination>
<dat:Destination>
<dat:Continent>Europe</dat:Continent>
<dat:Country>Spain</dat:Country>
<dat:State></dat:State>
<dat:City>Madrid</dat:City>
<dat:Providers>
<dat:ProviderType>Default</dat:ProviderType>
</dat:Providers>
</dat:Destination>
</dat:GetDestination>
</soapenv:Body>
</soapenv:Envelope>
I am trying to achieve this using PHP's built in SoapClient Class. When I run the following code it says "Login failure please check user name and password." But I am very much sure that both the username and password are correct as the same values are being used in other applications.
I think the problem is in the code below. Could you please tell me what is the mistake ?
try{
$client = new SoapClient($soap_url, array("trace" => 1));
$ns = 'http://touricoholidays.com/WSDestinations/2008/08/DataContracts';
$auth = array(
'username' => 'myUserName',
'password' => 'myPassword',
'culture' => 'en_US',
'version' => '8',
);
$header = new SoapHeader($ns, 'LoginHeader', $auth);
$client->__setSoapHeaders($header);
$res = $client->__soapCall("GetDestination", array());
var_dump($res);
}
catch(Exception $e)
{
echo $e->getMessage();
}
you should definitively use a WSDL to php generator that still uses the native SoapClient class such as the PackageGenerator project. It simply generates the PHP SDK according to the WSDL. Then you only have to use the generated classes to construct and send your request. The response is then an object using the generated classes.
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
$method ='MerchantFinancialOperationWS';
$configs = array(
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => false,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'local_cert' => $cert_file,
'passphrase' => $cert_password
);
if($debug) $configs['trace'] = true;
if(substr($url, -5) != '?WSDL') $url.= '?WSDL';
$webService = new SoapClient($url, $configs);
$data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fin="http://financial.services.merchant.channelmanagermsp.sibs/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://financial.services.merchant.channelmanagermsp.sibs/MerchantFinancialOperationWS/requestFinancialOperationRequest</wsa:Action>
<wsa:ReplyTo>
<wsa:Address>https://enderecodeteste.pt</wsa:Address>
</wsa:ReplyTo>
</soapenv:Header>
<soapenv:Body>
<fin:requestFinancialOperation>
<arg0>
<messageType>N0003</messageType>
<aditionalData>TESTE</aditionalData>
<alias>
<aliasName>351#994999999</aliasName>
<aliasTypeCde>001</aliasTypeCde>
</alias>
<financialOperation>
<amount>400</amount>
<currencyCode>9782</currencyCode>
<operationTypeCode>022</operationTypeCode>
<merchantOprId>11111</merchantOprId>
</financialOperation>
<merchant>
<iPAddress>255.255.255.255</iPAddress>
<posId>880924 </posId>
</merchant>
<messageProperties>
<channel>01</channel>
<apiVersion>1</apiVersion>
<channelTypeCode>VPOS</channelTypeCode>
<networkCode>MULTIB</networkCode>
<serviceType>01</serviceType>
<timestamp>2014-10-31T13:58:49.2934+01:00</timestamp>
</messageProperties>
</arg0>
</fin:requestFinancialOperation>
</soapenv:Body>
</soapenv:Envelope>';
$result = $webService->requestFinancialOperation($data);
I've been trying to implement a soap request with a pem certificate and i'm just getting out of ideas. I know my code should be all wrong but i have no idea what the right direction is. I've been researching but found little no none documentation on this and the team behind the webservice i have to use also wasn't able to help.
I can already communicate with the service using SoapUI so i know the webservice works
Part of the issue is you're sending XML when you may not need to. PHP's built-in SOAP client will handle the XML for you, so you can focus on the objects (the O in SOAP!). You need to construct a data structure (object or array) and pass that to the operation you want to run. First look for the signature of the operation you want using:
$webService = new SoapClient($url, $configs);
var_dump($webService->__getFunctions());
This gives you the API - note that it indicates the data structures it expects in both the input parameters and the output. To see what those data structures look like:
var_dump($webService->__getTypes());
Now you can construct a PHP object with the same fields and structure and pass it in. Your code will look something along these lines:
$webService = new SoapClient($url, $configs);
$parameter = new stdClass();
$parameter->someField = 'N0003';
$parameter->anotherField = 'TESTE';
$result = $webService->requestFinancialOperation($parameter);