I have a script that consumes a webservice through SOAP. I'm wondering why I don't receive a response from the server/endpoint URL. The other side said that they're receiving my requests so it means the script works. The only problem is that it doesn't give me a response. I also tried to get the last request, last request header and last response but nothing happens.
Do you have any idea why this is happening?
Here's my code:
$wsdl = "http://imupost.co.za/momentum/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0";
echo("Post to URL: {$momurl}\n");
$username = "817221";
$password = "1234";
echo("<pre>");
$client = new SoapClient ($wsdl, array('location' => $momurl, 'style' => SOAP_DOCUMENT, 'trace' => 1, 'soap_version' => SOAP_1_1, 'exceptions' => true, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'ssl_method' => SOAP_SSL_METHOD_TLS));
$header='
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-45">
<wsse:Username>'.$username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
';
$headerSoapVar = new SoapVar($header,XSD_ANYXML);
$soapheader = new SoapHeader('wsse', "Security" , $headerSoapVar , true);
$client->__setSoapHeaders($soapheader);
$params['createLead'] = array(
'LeadSourceId' => '07d3d6fe-7682-e311-a16d-005056b81ea8',
'AffiliateLeadReference' => '852800020',
'Title' => array('Code' => '852800018'),
'Initials' => 'MH',
'PreferredName' => 'Jane',
'FirstName' => 'Hudson',
'LastName' => 'Craig',
'PreferredCorrespondenceLanguage' => array('Code' => '852800001'),
'PreferredCommunicationMethod' => array('Code' =>'852800000'),
'HomePhoneNumber' => '0725222427',
'BusinessPhoneNumber' => '0725584155',
'MobilePhoneNumber' => '0723694259',
'EmailAddress' => 'jhudson#gmail.com',
'Notes' => 'IMU',
'ProductCategories' => array('Code' => '9c7d3878-5295-e211-9330-005056b81ea8', 'Description' => 'Health - Personal')
);
$result = $client->__soapCall("createLead", array($params));
echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
echo "RESPONSE:\n" . $client->__getLastResponse() . "\n";
print_r($client->__getLastRequestHeaders());
I would suggest using a try catch.
try {
$client->__soapCall("createLead", array($params));
echo $client->__getLastResponse();
} catch (Exception $e) {
echo "<pre>Exception: ".print_r($e, true)."</pre>\n";
}
Related
I'm trying to make a soap call and it returns a "Bad request" error.
The example call is:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://centric.eu/services/CS/Trade/Standard/WS/" xmlns:cen="http://schemas.datacontract.org/2004/07/Centric.CS.Trade.Standard.WS.StockService.Contract.Request">
<soapenv:Header>
<ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ws:UsernameToken>
<ws:Username>username</ws:Username>
<ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</ws:Password>
</ws:UsernameToken>
</ws:Security>
</soapenv:Header>
<soapenv:Body>
<ws:GetStock>
<ws:request>
<cen:StockRequests>
<!--Zero or more repetitions:-->
<cen:StockRequest>
<cen:CustomerNo>123</cen:CustomerNo>
<cen:Division>AGU_NL</cen:Division>
<cen:Item>113504</cen:Item>
<cen:Language>NL</cen:Language>
<cen:Login>123</cen:Login>
</cen:StockRequest>
</cen:StockRequests>
</ws:request>
</ws:GetStock>
</soapenv:Body>
</soapenv:Envelope>
I use the following code:
$soapclient = new \SoapClient($url, array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 9,
'trace' => true,
'exceptions' => 1,
'cache_wsdl' => 1,
));
$xml = '
<ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<ws:UsernameToken>
<ws:Username>'.$username.'</ws:Username>
<ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</ws:Password>
</ws:UsernameToken>
</ws:Security>
';
$soapheader = new \SoapHeader(
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
'Security',
new \SoapVar($xml, XSD_ANYXML),
true);
$soapclient->__setSoapHeaders($soapheader);
try {
$soapclient->__soapCall('GetStock',
array(
'CustomerNo' => 123,
'Division' => 'AGU_NL',
'Item' => '113504',
'Language' => 'NL',
'Login' => '123',
)
);
} catch(\SoapFault $e) {
echo '<pre>';
print_r($e->getMessage());
echo '</pre>';
}
The response I get is: fault code: HTTP, fault string: Bad Request
I am not entirely sure whether I created the request and called the method correctly.
Any help will be appreciated
Thanks
You are probably better off not trying to construct the xml manually. Try something along these lines instead:
$url = 'https://webservices.abcb2b.eu/Centric/CS/Trade/csprod/StockService.svc?wsdl';
$username = 'username';
$password = 'pass';
$client = new SoapClient($url, array('trace' => 1, "exception" => 0));
$wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$usernameToken = new SoapVar(array(
new SoapVar(array(
new SoapVar($username, XSD_STRING, null, null, 'Username', $wssNamespace),
new SoapVar($password, XSD_STRING, null, null, 'Password', $wssNamespace)
), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $wssNamespace)
), SOAP_ENC_OBJECT, null, null, null, $wssNamespace);
$client->__setSoapHeaders(new SoapHeader($wssNamespace, 'Security', $usernameToken));
try {
$client->GetStock(array(
'request' => array(
'StockRequests' => array(
'StockRequest' => array(
'CustomerNo' => 123,
'Division' => 'AGU_NL',
'Item' => '113504',
'Language' => 'NL',
'Login' => '123',
)
)
)
));
} catch(\SoapFault $e) {
echo '<pre>';
print_r($e->getMessage());
echo '</pre>';
}
The reason you are getting Bad Request is because you are not formatting your request well, try to make should there are no spaces in between your request
require_once('modules/FedEx/RateAvailableServicesService_v18_php/library/fedex-common.php5');
$path_to_wsdl = PATH."modules/FedEx/RateAvailableServicesService_v18_php/RateService_v18.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
//'ParentCredential' => array(
//'Key' => $this->getProperty('key'),
//'Password' => $this->getProperty('password')
//),
'UserCredential' => array(
'Key' => $this->getProperty('key'),
'Password' => $this->getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => $this->getProperty('shipaccount'),
'MeterNumber' => $this->getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '1'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
// Service Type and Packaging Type are not passed in the request
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['Shipper'] = array(
'Address'=> array('StreetLines' => array($UL->str_add1,$UL->str_add2),'City' => $UL->city_name,'StateOrProvinceCode' => $UL->state_name,'PostalCode' => $UL->zipcode,'CountryCode' => $UL->country_code));
$request['RequestedShipment']['Recipient'] = array(
'Address'=>array('StreetLines' => array($this->session->get('shipping_address1'),$this->session->get('shipping_address2')),'City' => $shipping_city,'StateOrProvinceCode' => $shipping_state,'PostalCode' => $this->session->get('shipping_postal_code'),'CountryCode' => $country_code,'Residential' => false));
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => $this->getProperty('billaccount'),
'Contact' => null,
'Address' => array(
'CountryCode' => COUNTRY_CODE
)
)
)
);
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'SequenceNumber' => 1,
'GroupPackageCount' => 1,
'Weight' => array(
'Value' => $UL->weight//,
//'Units' => 'LB'
),
'Dimensions' => array(
'Length' => $UL->length,
'Width' => $UL->width,
'Height' => $UL->height//,
//'Units' => 'IN'
)
)
);
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
echo 'Rates for following service type(s) were returned.'. Newline. Newline;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td>';
if(is_array($response -> RateReplyDetails)){
foreach ($response -> RateReplyDetails as $rateReply){
$this->printRateReplyDetails($rateReply);
}
}else{
$this->printRateReplyDetails($response -> RateReplyDetails);
}
echo '</table>'. Newline;
printSuccess($client, $response);
}else{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
Here is error exception which i am getting
Fault
Code:SOAP-ENV:Server
String:Fault
Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v18"><SOAP-ENV:Body><ns1:RateRequest><ns1:WebAuthenticationDetail><ns1:UserCredential><ns1:Key>AndJurrJfCvvWZWn</ns1:Key><ns1:Password>Rps8Pl4jF9zGp5wiEpDRhKiHo</ns1:Password></ns1:UserCredential></ns1:WebAuthenticationDetail><ns1:ClientDetail><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:MeterNumber>107714405</ns1:MeterNumber></ns1:ClientDetail><ns1:TransactionDetail><ns1:CustomerTransactionId> *** Rate Available Services Request using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>18</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>1</ns1:Minor></ns1:Version><ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit><ns1:RequestedShipment><ns1:ShipTimestamp>2016-03-30T18:35:41+05:30</ns1:ShipTimestamp><ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType><ns1:ServiceType>INTERNATIONAL_PRIORITY</ns1:ServiceType><ns1:Shipper><ns1:Address><ns1:StreetLines>SUITE 5A-1204</ns1:StreetLines><ns1:StreetLines>799 E DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode></ns1:Address></ns1:Shipper><ns1:Recipient><ns1:Address><ns1:StreetLines>795 E</ns1:StreetLines><ns1:StreetLines>DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode><ns1:Residential>false</ns1:Residential></ns1:Address></ns1:Recipient><ns1:ShippingChargesPayment><ns1:PaymentType>SENDER</ns1:PaymentType><ns1:Payor><ns1:ResponsibleParty><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:Address><ns1:CountryCode>KWI</ns1:CountryCode></ns1:Address></ns1:ResponsibleParty></ns1:Payor></ns1:ShippingChargesPayment><ns1:PackageCount>1</ns1:PackageCount><ns1:RequestedPackageLineItems><ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount><ns1:Weight>
<ns1:Value>20</ns1:Value></ns1:Weight><ns1:Dimensions>
<ns1:Length>8</ns1:Length><ns1:Width>10</ns1:Width>
<ns1:Height>10</ns1:Height></ns1:Dimensions></ns1:RequestedPackageLineItems>
</ns1:RequestedShipment></ns1:RateRequest></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Since you have trace on, you should look at the actual request/response data. When I took your raw POST data above (in which you shouldn't have posted your account/key info) I get back a schema validation error. Syntax looks correct but the country code for payor is KWI but should be US. I'd suggest you add some code to log the request and responses...
$soap_response_hdr = $client->__getLastResponseHeaders() ;
$soap_response = $client->__getLastResponse() ;
$soap_request_hdr = $client->__getLastRequestHeaders() ;
$soap_request = $client->__getLastRequest() ;
I'm trying to send some data to Royal Mail API, but i receive a message saying: E0004 Failed Schema Validation. Follow the code i used to create the request:
$api_password = "xxxx";
$api_username = "xxx#xxx.comAPI";
$api_application_id = "xxxxxx";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "xxxxx";
$api_service_enhancements = "";
$data = new ArrayObject();
$data->order_tracking_id = "";
$data->shipping_name = "Felipe";
$data->shipping_company = "splash";
$data->shipping_address1 = "23, St johns road";
$data->shipping_address2 = "";
$data->shipping_town = "london";
$data->shipping_postcode = "NW11 0PE";
$data->order_tracking_boxes = "0";
$data->order_tracking_weight = "1500";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz . xyz . pack("H**", sha1($api_password));
$passwordDigest = base64_encode(pack('ZH**',sha1($nonce_date_pwd)));
$ENCODEDNONCE = base64_encode($nonce);
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['local_cert'] = "certificate.pem";
$soapclient_options['passphrase'] = $api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
$soapclient_options['soap_version'] = 'SOAP_1_1';
//'soap_version' => SOAP_1_2,
//launch soap client
$client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
// print_r($client);
//headers needed for royal mail
$HeaderObjectXML = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
<wsse:Username>'.$api_username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passwordDigest.'</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$ENCODEDNONCE.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
//push the header into soap
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
//build the request
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2.0',
'identification' => array(
'applicationId' => $api_application_id,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array('code' => 'Delivery'),
'serviceOccurence' => '1',
'serviceType' => array('code' => $api_service_type),
'serviceOffering' => array('serviceOfferingCode' => array('code' => $api_service_code)),
'serviceFormat' => array('serviceFormatCode' => array('code' => $api_service_format)),
'shippingDate' => date('Y-m-d'),
'recipientContact' => array('name' => $data->shipping_name, 'complementaryName' => $data->shipping_company),
'recipientAddress' => array('addressLine1' => $data->shipping_address1, 'addressLine2' => $data->shipping_address2, 'postTown' => $data->shipping_town, 'postcode' => $data->shipping_postcode),
'items' => array('item' => array( 'numberOfItems' => $data->order_tracking_boxes, 'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')), 'value' => ($data->order_tracking_weight) //weight of each individual item
)
)
)
)
);
$body = new SoapVar( $request, SOAP_ENC_OBJECT );
//if any enhancements, add it into the array
if($api_service_enhancements != "") {
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
}
try {
$response = $client->__soapCall( 'createShipment', array($request), array('soapaction' => 'https://api.royalmail.com/shipping/onboarding') );
print_r($response);
} catch (Exception $e) {
//catch the error message and echo the last request for debug
//print_r($e);
echo $e->getMessage();
echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
// die;
}
Follow the Request the code is creating:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.royalmailgroup.com/integration/core/V1" xmlns:ns2="http://www.royalmailgroup.com/api/ship/V2" xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
<wsse:Username>xxx#xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">ztyoDZ0RtlCehYvlhEYYCOCXt0CY=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MjA5MzA5jNjU1MQ==</wsse:Nonce>
<wsu:Created>2015-03-17T10:56:02Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:createShipmentRequest>
<ns2:integrationHeader><ns1:dateTime>2015-03-17T10:56:02</ns1:dateTime><ns1:version>2.0</ns1:version><ns1:identification><ns1:applicationId>xxxxx</ns1:applicationId><ns1:transactionId>730222611</ns1:transactionId></ns1:identification></ns2:integrationHeader>
<ns2:requestedShipment>
<ns2:shipmentType><code>Delivery</code></ns2:shipmentType>
<ns2:serviceType><code>D</code></ns2:serviceType>
<ns2:serviceOffering><serviceOfferingCode><code>SD1</code></serviceOfferingCode></ns2:serviceOffering>
<ns2:serviceFormat><serviceFormatCode><code></code></serviceFormatCode></ns2:serviceFormat>
<ns2:shippingDate>2015-03-17</ns2:shippingDate>
<ns2:recipientContact>
<ns2:name>Felipe</ns2:name>
<ns2:complementaryName>splash</ns2:complementaryName>
</ns2:recipientContact>
<ns2:recipientAddress>
<addressLine1>27, St johns road</addressLine1>
<addressLine2></addressLine2>
<postTown>london</postTown>
<postcode>NW11 0PE</postcode>
</ns2:recipientAddress>
<ns2:items>
<ns2:item>
<ns2:numberOfItems>0</ns2:numberOfItems>
<ns2:weight><unitOfMeasure><unitOfMeasureCode><code>g</code></unitOfMeasureCode></unitOfMeasure><value>1500</value></ns2:weight>
</ns2:item>
</ns2:items>
</ns2:requestedShipment></ns2:createShipmentRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
Follow the example request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.royalmailgroup.com/integration/core/V1" xmlns:v2="http://www.royalmailgroup.com/api/ship/V2">
<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-xxxxxxxxxxxxxx"><wsse:Username>xxxx#xxx.comAPI</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">gShxrkDCihB04r5iG+xA+p7aqMU=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">Kxv2sk4hXnvAHLbOVIsuvw==</wsse:Nonce><wsu:Created>2015-03-09T08:01:28.132Z</wsu:Created></wsse:UsernameToken></wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v2:createShipmentRequest>
<v2:integrationHeader>
<v1:dateTime>2015-03-08T08:52:03</v1:dateTime>
<v1:version>2</v1:version>
<v1:identification>
<v1:applicationId>xxxxxxxxx</v1:applicationId>
<v1:transactionId>730222611</v1:transactionId>
</v1:identification>
</v2:integrationHeader>
<v2:requestedShipment>
<v2:shipmentType>
<code>Delivery</code>
</v2:shipmentType>
<v2:serviceOccurrence>1</v2:serviceOccurrence>
<v2:serviceType>
<code>D</code>
</v2:serviceType>
<v2:serviceOffering>
<serviceOfferingCode>
<code>SD1</code>
</serviceOfferingCode>
</v2:serviceOffering>
<v2:serviceFormat>
<serviceFormatCode/>
</v2:serviceFormat>
<v2:signature>1</v2:signature>
<v2:shippingDate>2015-02-09</v2:shippingDate>
<v2:recipientContact>
<v2:name>Mr Tom Smith</v2:name>
<v2:complementaryName>Department 98</v2:complementaryName>
<v2:telephoneNumber>
<countryCode>0044</countryCode>
<telephoneNumber>07801123456</telephoneNumber>
</v2:telephoneNumber>
<v2:electronicAddress>
<electronicAddress>tom.smith#royalmail.com</electronicAddress>
</v2:electronicAddress>
</v2:recipientContact>
<v2:recipientAddress>
<addressLine1>3 Vantage Walk</addressLine1>
<postTown>Hastings</postTown>
<postcode>TN38 0YP</postcode>
<country>
<countryCode>
<code>GB</code>
</countryCode>
</country>
</v2:recipientAddress>
<v2:items>
<v2:item>
<v2:numberOfItems>1</v2:numberOfItems>
<v2:weight>
<unitOfMeasure>
<unitOfMeasureCode>
<code>g</code>
</unitOfMeasureCode>
</unitOfMeasure>
<value>100</value>
</v2:weight>
</v2:item>
</v2:items>
<v2:customerReference>CustSuppRef1</v2:customerReference>
<v2:senderReference>SenderReference1</v2:senderReference>
</v2:requestedShipment>
</v2:createShipmentRequest>
</soapenv:Body>
</soapenv:Envelope>
I'm really stuck on it, nothing i try looks to work. I feel like it's something really small that I'm not been able to find.
Any help would be great.
Thanks
I have written a script that should connect to a secure web service (ws-security). However, when running the script, I'm getting this error:
Error: SOAP-ERROR: Encoding: object has no 'createLead' property
I'm using this code:
<?php
$wsdl = "http://localhost/test/wsdl-src/CRMLeadService.wsdl";
$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/";
echo "Post to URL: {$momurl}\n";
$username = '817221';
$password = '1234';
//Perform Request
$client = new SoapClient ($wsdl, array('loacation' => $momurl));
$security = array('UsernameToken' => array(
'Username'=>"$username",
'Password'=>"$password"
));
$header = new SoapHeader('wsse','Security',$security, false);
$client->__setSoapHeaders($header);
print_r($client);
echo "<br />";
print_r( $client->__getFunctions() ); //Available Function
$params = array(
'LeadSourceId' => '23627e70-a29e-e211-b8a8-005056b81ebe',
'AffiliateLeadReference' => '5465546hdfh5sggd52',
'Title' => '852800018',
'Initials' => 'MD',
'PreferredName' => 'Marius',
'FirstName' => 'Marius',
'LastName' => 'Drew',
'PreferredCorrespondenceLanguage' => '852800001',
'PreferredCommunicationMethod' => '852800000',
'Campaign' => '',
'HomePhoneNumber' => '0723621762',
'BusinessPhoneNumber' => '0723621762',
'MobilePhoneNumber' => '0723621762',
'EmailAddress' => 'mdrew#gmail.com',
'Notes' => 'IMU',
'ProductCategories' => array('Code' => 'd000083d-229c-e211-b8a8-005056b81ebe')
);
print_r($params);
try {
echo $result = $client->__soapCall('createLead',array('parameters'=>$params));
} catch (Exception $e) {
$msgs = $e->getMessage();
echo "Error: $msgs";
}
?>
The WSDL and XSD files can be downloaded here:
http://sdrv.ms/16KC8o4
Any help would be appreciated. Thanks!
I need to send a SOAP request to Estes to retrieve rate quotes. I'm having trouble doing this as the other APIs I have worked with either post the XML or use a URL string. This is a bit different for me.
I believe my problem is that I cannot figure out the array that needs to be sent for the request.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://ws.estesexpress.com/ratequote" xmlns:rat1="http://ws.estesexpress.com/schema/2012/12/ratequote">
<soapenv:Header>
<rat:auth>
<rat:user>XXXXX</rat:user>
<rat:password>XXXX</rat:password>
</rat:auth>
</soapenv:Header>
<soapenv:Body>
<rat1:rateRequest>
<rat1:requestID>XXXXXX</rat1:requestID>
<rat1:account>XXXXXXX</rat1:account>
<rat1:originPoint>
<rat1:countryCode>XX</rat1:countryCode>
<rat1:postalCode>XXXXX</rat1:postalCode>
<rat1:city>XXXXXX</rat1:city>
<rat1:stateProvince>XX</rat1:stateProvince>
</rat1:originPoint>
<rat1:destinationPoint>
<rat1:countryCode>XX</rat1:countryCode>
<rat1:postalCode>XXXXX</rat1:postalCode>
</rat1:destinationPoint>
<rat1:payor>X</rat1:payor>
<rat1:terms>XX</rat1:terms>
<rat1:stackable>X</rat1:stackable>
<rat1:baseCommodities>
<rat1:commodity>
<rat1:class>X</rat1:class>
<rat1:weight>XXX</rat1:weight>
</rat1:commodity>
</rat1:baseCommodities>
</rat1:rateRequest>
</soapenv:Body>
</soapenv:Envelope>
This was the code I was using before and it is not working.
<?php
$client = new SoapClient("https://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl");
$request_object = array(
"header"=>array(
"auth"=>array(
"user"=>"XXXXX",
"password"=>"XXXXX",
)
),
"rateRequest"=>array(
"requestID"=>"XXXXXXXXXXXXXXX",
"account"=>"XXXXXX",
),
"originPoint"=>array(
"countryCode"=>"XX",
"postalCode"=>"XXXXX",
"city"=>"XXXXX",
"stateProvince"=>"XX",
),
"destinationPoint"=>array(
"countryCode"=>"XX",
"postalCode"=>"XXXXX",
),
"payor"=> "X",
"terms"=> "XXXX",
"stackable"=> "X",
"baseCommodities"=>array(
"commodity"=>array(
"class"=>"XX",
"weight"=>"XXXX",
)
),
);
$result = $client->rateRequest(array("request"=>$request_object));
var_dump($result);
?>
Here is the error
Fatal error: Uncaught SoapFault exception: [Client] Function ("rateRequest") is not a valid method for this service in /home/content/54/11307354/html/test/new/estes.php:36
Stack trace: #0 /home/content/54/11307354/html/test/new/estes.php(36): SoapClient->__call('rateRequest', Array) #1 /home/content/54/11307354/html/test/new/estes.php(36):
SoapClient->rateRequest(Array) #2 {main} thrown in /home/content/54/11307354/html/test/new/estes.php on line 36
This is my $params array that is passed to the Estes API
$params = array(
"requestID" => "xxxxxxxx",
"account" => "xxxxxxxx",
"originPoint" => array('countryCode' => 'US', 'postalCode' => $fromzip),
"destinationPoint" => array('countryCode' => 'US', 'postalCode' => $shipzip),
"payor" => 'T',
"terms" => 'PPD',
"stackable" => 'N',
"baseCommodities" => array('commodity' => $comArray ),
"accessorials" => array('accessorialCode' => $accArray)
If there are no accessorials, that array needs to be deleted from the $params array
);
// remove accessorials entry if no accessorial codes
if(sizeof($accArray) == 0){
$params = array_slice($params, 0, 8); // remove accesorials entry
}
THis is how I build the commodities array from a class array & a weight
array:
// load the $params commodities array
$comArray = array();
for ($i=0; $i<count($class_tbl); $i++) {
$comArray[] = array('class'=>$class_tbl[$i], 'weight'=>$weight_tbl[$i]);
}
The following code formats the accessorials array
if($inside == "Yes") {
$accArray[$i] = "INS";
++$i;
}
if($liftgate == "Yes") {
$accArray[$i] = "LGATE";
++$i;
}
if($call == "Yes") {
$accArray[$i] = "NCM";
++$i;
}
The Estes destination accessorial code also should be added to the $accArray array if delivery is to other than a business (for instance school. church, etc.)
See if anything in our soap call helps. We are doing the soap call like this:
// define transaction arrays
$url = "http://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl";
$username = 'xxxxxxxx';
$password = 'xxxxxxxx';
// setting a connection timeout of five seconds
$client = new SoapClient($url, array("trace" => true,
"exceptions" => true,
"connection_timeout" => 5,
"features" => SOAP_WAIT_ONE_WAY_CALLS,
"cache_wsdl" => WSDL_CACHE_NONE));
$old = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 5);
//Prepare SoapHeader parameters
$cred = array(
'user' => $username,
'password' => $password
);
$header = new SoapHeader('http://ws.estesexpress.com/ratequote', 'auth', $cred);
$client->__setSoapHeaders($header);
$params = array(
"requestID" => "xxxxxxxx",
"account" => "xxxxxxxx",
"originPoint" => array('countryCode' => 'US', 'postalCode' => $fromzip),
"destinationPoint" => array('countryCode' => 'US', 'postalCode' => $shipzip),
"payor" => 'T',
"terms" => 'PPD',
"stackable" => 'N',
"baseCommodities" => array('commodity' => $comArray ),
"accessorials" => array('accessorialCode' => $accArray)
);
// remove accessorials entry if no accessorial codes
if(count($accArray) == 0){
$params = array_slice($params, 0, 8); // remove accesorials entry
}
// call Estes API and catch any errors
try {
$reply = $client->getQuote($params);
}
catch(SoapFault $e){
// handle issues returned by the web service
//echo "Estes soap fault<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
catch(Exception $e){
// handle PHP issues with the request
//echo "PHP soap exception<br>" . $e . "<br>";
$edit_error_msg = "Estes quote API timed out or failed to return a quote";
return "0.00";
}
unset($client);
ini_set('default_socket_timeout', $old);
// print_r($reply);
Looking up the WSDL with a validator it looks like the two methods available are echo and getQuote.
Looking at the WSDL itself you can see that too:
<wsdl:operation name="getQuote">
<wsdl:input name="rateRequest" message="tns:rateRequestMsg"></wsdl:input>
<wsdl:output name="quoteInfo" message="tns:rateQuoteMsg"></wsdl:output>
<wsdl:fault name="schemaErrorMessage" message="tns:schemaErrorMsg"></wsdl:fault>
<wsdl:fault name="generalErrorMessage" message="tns:generalErrorMsg"></wsdl:fault>
</wsdl:operation>
Try calling getQuote instead of rateRequest.
$result = $client->__soapCall('getQuote', array("request"=>$request_object));