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
Related
I'm trying to connect to Royal Mail shipping API, but I'm receiving the famous Could not connect to host.
$api_password = "****";
$api_username = "****";
$api_application_id = "****";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "****";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = zyz(copy from sample);
$ENCODEDNONCE = zyz(copy from sample);
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['local_cert'] = "CA2+Splash+Felipe+RM10001654+usr.p12";
$soapclient_options['passphrase'] = $api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = '****';
//launch soap client
$client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
(setting header)
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
(setting request part)
if($api_service_enhancements != "") {
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
}
//try make the call
try {
$response = $client->__soapCall('createShipment', array($request), array('soapaction' => '***api-link***') );
} catch (Exception $e) {
//catch the error message and echo the last request for debug
echo $e->getMessage();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
die;
}
Is it correct the way I'm setting the connection and the local cert?
Is any information I'm missing?
Thanks & Regards
Follow my final code :) this one works for sure. Even have the retry in case the server is buzy, enjoy.
<?php
//ini_set('soap.wsdl_cache_enabled', '1');
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
class royalmaillabelRequest
{
private $apiapplicationid = "insert urs";
private $api_password = "insert urs";
private $api_username = "insert urs"; //"rxxxxxAPI"
private $api_certificate_passphrase = "insert urs";
private $locationforrequest = 'https://api.royalmail.com/shipping/onboarding'; //live 'https://api.royalmail.com/shipping' onbording 'https://api.royalmail.com/shipping/onboarding'
private $api_service_enhancements = "";
private function preparerequest(){
//PASSWORD DIGEST
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = nyz(copy from sample);
$ENCODEDNONCE = (copy from sample);
//SET CONNECTION DETAILS
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['stream_context'] = stream_context_create(
array('http'=>
array(
'protocol_version'=>'1.0'
, 'header' => 'Connection: Close'
)
)
);
$soapclient_options['local_cert'] = dirname(__FILE__) . "/certificate.pem";
$soapclient_options['passphrase'] = $this->api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = $this->locationforrequest;
$soapclient_options['soap_version'] = 'SOAP_1_1';
//launch soap client
$client = new SoapClient(dirname(__FILE__) . "/SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
//headers needed for royal mail//D8D094Fd2716E3Es142588808s317
$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-D8D094FC22716E3EDE14258880881317">
<wsse:Username>'.$this->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);
return $client;
}
public function CreateShippiment($data){
$request = $this->buildCreateshippiment($data);
$type = 'createShipment';
return $this->makerequest($type, $request);
}
public function PrintLabel($shipmentNumber,$order_tracking_id){
$time = gmdate('Y-m-d\TH:i:s');
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $order_tracking_id
)
),
'shipmentNumber' => $shipmentNumber,
'outputFormat' => 'PDF',
);
$type = 'printLabel';
$response = $this->makerequest($type, $request);
return $response->label;
}
private function makerequest($type, $request){
$client = $this->preparerequest();
$response = false;
$times = 1;
while(true){
try {
$response = $client->__soapCall( $type, array($request), array('soapaction' => $this->locationforrequest) );
// echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
} catch (Exception $e) {
print_r($e);
if($e->detail->exceptionDetails->exceptionCode == "E0010" && $times <= 25){
sleep(1.5);
$times++;
continue;
}else{
echo $e->getMessage();
echo "<pre>";
print_r($e->detail);
echo $client->__getLastResponse();
echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
}
}
break;
}
return $response;
}
private function buildCreateshippiment($data2) {
$time = gmdate('Y-m-d\TH:i:s');
$data = new ArrayObject();
foreach ($data2 as $key => $value)
{
$data->$key = $value;
}
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array('code' => 'Delivery'),
'serviceOccurrence' => 1,
'serviceType' => array('code' => $data->api_service_type),
'serviceOffering' => array('serviceOfferingCode' => array('code' => $data->api_service_code)),
'serviceFormat' => array('serviceFormatCode' => array('code' => $data->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,
)
)
),
//'signature' => 0,
)
);
if($data->api_service_enhancements == 6 && $data->api_service_type == 1){
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $data->api_service_enhancements)));
}
return $request;
}
}
docs.oasis-open.org is slow and doesn't respond in time.
Download oasis-200401-wss-wssecurity-utility-1.0.xsd and modify ShippingAPI_V2_0_8.wsdl to use local version.
Your location looks wrong..
$soapclient_options['location'] = '****';
Shouldn't this look like this..
$soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
I am logging into a server with soap and retreiving a token, no problem....
I then add the token to the soap:header.
This is what I am trying create.
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<WSAuthorization xmlns="http://url.com/testing/">
<Token>string</Token>
</WSAuthorization>
</soap12:Header>
<soap12:Body>
<ImportDrugTest xmlns="http://url.com/testing/">
<specimenID>int</specimenID>
<midasNumber>string</midasNumber>
<specimenComments>string</specimenComments>
<nonRXDrugsUsed>string</nonRXDrugsUsed>
<testCode>string</testCode>
<testDate>dateTime</testDate>
<testResult>string</testResult>
<collectionDate>dateTime</collectionDate>
<lastName>string</lastName>
<firstName>string</firstName>
<middleName>string</middleName>
<CRUDFlag>string</CRUDFlag>
</ImportDrugTest>
</soap12:Body>
</soap12:Envelope>
This is what I am getting
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/testing/">
<soap-env:header>
<ns1:wsauthorization />
</soap-env:header>
<soap-env:body>
<ns1:importdrugtest>
<ns1:specimenid>605431024</ns1:specimenid>
<ns1:midasnumber>7700MD2005000001.00</ns1:midasnumber>
<ns1:specimencomments>Miscellaneous</ns1:specimencomments>
<ns1:nonrxdrugsused>N/A</ns1:nonrxdrugsused>
<ns1:testcode>025000</ns1:testcode>
<ns1:testdate>2012-09-24</ns1:testdate>
<ns1:testresult>Negative</ns1:testresult>
<ns1:collectiondate>2012-09-25</ns1:collectiondate>
<ns1:lastname>Last</ns1:lastname>
<ns1:firstname>First</ns1:firstname>
<ns1:middlename>Middle</ns1:middlename>
<ns1:crudflag>C</ns1:crudflag>
</ns1:importdrugtest>
</soap-env:body>
</soap-env:envelope>
Here is my code. Note: I have already stared a new SoapClient() and regeived the token.
$ns = 'http://url.com/testing/';
// $headerParams = array('WSAuthorization'=>array('token'=>$token)); tried this also
$headerParams = array('token'=>$token);
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);
$client->__setSoapHeaders($header);
$param = array('ImportTest' => array(
'specimenID' => '0605431024',
'midasNumber' => '7700MD2005000001.00',
'county' => '03',
'site' => '00',
'specimenComments' => 'Miscellaneous',
'nonRXDrugsUsed' => 'N/A',
'testCode' => '025000',
'testDate' => '2012-09-24',
'testResult' => 'Negative',
'collectionDate' => '2012-09-25',
'lastName' => 'Last',
'firstName' => 'First',
'middleName' => 'Middle',
'CRUDFlag' => 'C'
));
$result = $client->__soapCall('ImportDrugTest', $param);
Update 12/31/14:
I modified the code and added print_r($header):
$ns = "http://url.com/testing/";
$headerParams = array('token'=>$token);
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);
print_r($header);
$client->__setSoapHeaders(array($header)); // even tried $client->__setSoapHeaders($header);
I get this:
SoapHeader Object
(
[namespace] => http://url.com/testing/
[name] => WSAuthorization
[data] => Array
(
[token] => UDjVSzGt9J4fKuRuoFHau3gy4CoLo//VlnuZv5oy5tjKPffIeSc+dx7EEDIfosVkVHDD0G/ZBANnCzPmRBo6CIusRL5rak5QdYI9jD7209c=
)
[mustUnderstand] =>
)
But __getLastRequest() gives me this:
<soap-env:header>
<ns1:wsauthorization />
</soap-env:header>
What am I missing?
This works:
$headerParams = array('Token' => $token);
$header = new SoapHeader($NameSpace, 'WSAuthorization', $headerParams, false);
The problem I was having was caused by the token not being parsed from the response.
i wanna create soap request as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.0">
<soapenv:Header/>
<soapenv:Body>
<ns:updateUser sequence="?">
<!--You have a CHOICE of the next 2 items at this level-->
<uuid>{74932749237942794729473927493829}</uuid>
<userid>?</userid>
<associatedGroups>
<!--Zero or more repetitions:-->
<userGroup>
<name>Standard CTI Enabled</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CTI Enabled</userRole>
</userRoles>
</userGroup>
<userGroup>
<name>Standard CCM End Users</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CCM End Users</userRole>
</userRoles>
</userGroup>
</associatedGroups>
</ns:updateUser>
</soapenv:Body>
</soapenv:Envelope>
I have this as my code so far:
$userId = "example#mydomain.com";
$retAccessWebex["UserUuid"] = "{74932749237942794729473927493829}"; //sample userUuid
$userGroup = array();
$userRoleCTI = array("Standard CTI Enabled");
$userGroup[] = array(
"name" => "Standard CTI Enabled",
"userRoles" => array(
"userRole" => $userRoleCTI,
)
);
$userRoleCCM = array("Standard CCM End Users");
$userGroup[] = array(
"name" => "Standard CCM End Users",
"userRoles" => array(
"userRole" => $userRoleCCM,
)
);
$param = array(
"uuid" => $retAccessWebex["UserUuid"],
"userid" => $userId,
"associatedGroups" => array(
array(
"userGroup" => $userGroup,
)
)
);
$mywsdl = "pathToSchemaWsdl/AXLAPI.wsdl";
$wsdl = "https://127.0.0.1:8443/axl/";
$client = new SoapClient($mywsdl,
array('trace' => true,
'exceptions' => true,
'location' => $wsdl,
'login' => 'administrator',
'password' => 'mtp455w0rd',
));
$response = $client->updateUser($param);
however, when executing, I get this error message:
Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR:
Encoding: object has no 'name' property
try to see what is in request
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();
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";
}
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));