I’m working on a commerce site on which orders are placed. To track that delivery I need to give a link to users with all the parameters from a form filled by user to create a delivery and track its status using UK Mail with the link provided in a mail.
I have to use UK Mail Web Service API. Can anyone show me how to do so? I am new to SOAP WSDL.
From my understanding i did this now how to go further? My code below its just basic client i need to:
-
authenticate login and use the authenticate token
-
I need to send the parameters to create a domestic assignments
-
I need to track the delivery status too
here is my updated code :
<?php
$LoginWebRequest = new stdClass();
$LoginWebRequest->Username = 'xxx cant show here xxx';
$LoginWebRequest->Password = 'xxx cant show here xxx';
//echo "<pre>"; print_r($LoginWebRequest); "</pre>"; exit;
$Login = new stdClass();
$Login->loginWebRequest = $LoginWebRequest;
//echo "<pre>"; print_r($Login); "</pre>"; exit;
$soapClient = new SoapClient('somewsdl?wsdl');
$LoginResponse = $soapClient->Login($Login);
//echo "<pre>"; print_r($LoginResponse); "</pre>"; exit;
$LoginResponse = $soapClient->Login($Login);
// -- till here my code runs fine and also gives the failed output but adding the code //below gives me error cant find out whats wrong
$AuthenticationToken = $LoginResponse->LoginResult->AuthenticationToken;
$AddDomesticConsignmentWebRequest = new stdClass();
$AddDomesticConsignmentWebRequest->Username = 'xxxxxx';
// setting the Authentication Token from the previous step
$AddDomesticConsignmentWebRequest->AuthenticationToken = $AuthenticationToken ;
// other properties are set here...
$AddDomesticConsignment = new stdClass();
$AddDomesticConsignment->request = $AddDomesticConsignmentWebRequest;
$soapClient = new SoapClient('https://svc?wsdl');
$AddDomesticConsignmentResponse = $soapClient->AddDomesticConsignment($AddDomesticConsignment);
?>
i have solved all and got my consignment no too just need to track my api
my xml is like this or u can check the pdf
Example XML Request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:thir="http://webapp-cl.internet-delivery.com/ThirdPartyIntegrationService">
<soap:Header/>
<soap:Body>
<thir:ConsignmentTrackingSearchV1>
<thir:UserName>mail.com</thir:UserName>
<thir:Password>123</thir:Password>
<thir:Token></thir:Token>
<thir:ConsignmentNumber>01161</thir:ConsignmentNumber>
<thir:IsPartialConsignmentNumber>false</thir:IsPartialConsignmentNumber>
<thir:CustomerReference></thir:CustomerReference>
<thir:IsPartialCustomerReference>false</thir:IsPartialCustomerReference>
<thir:DeliveryPostCode></thir:DeliveryPostCode>
<thir:MailingID></thir:MailingID>
<thir:MaxResults>100</thir:MaxResults>
</thir:ConsignmentTrackingSearchV1>
</soap:Body>
</soap:Envelope>
example xml response
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConsignmentTrackingSearchV1Response xmlns="http://webapp-cl.internet- delivery.com/ThirdPartyIntegrationService">
<ConsignmentTrackingSearchV1Result>
<ResultState>Successful</ResultState>
<ConsignmentResults>
<ConsignmentSearchResult>
<ConsignmentNumber>001161</ConsignmentNumber>
<CustomerRef1/>
<CustomerRef2/>
<SubCustomerRef1/>
<SubCustomerRef2/>
<DeliveryType/>
<ConsignmentStatus>Delivered</ConsignmentStatus>
<DateTimeDelivered>2010-02-11T12:00:00+00:00</DateTimeDelivered>
<ItemsDelivered>2</ItemsDelivered>
<RecipientName>robin</RecipientName>
<DeliveryComments/>
<ExpectedDeliveryDate>2010-02-11T00:00:00</ExpectedDeliveryDate>
<DeliveryService>Next Day</DeliveryService>
<TotalItems>2</TotalItems>
<Consignmentkey>22</Consignmentkey>
</ConsignmentSearchResult>
</ConsignmentResults>
</ConsignmentTrackingSearchV1Result>
</ConsignmentTrackingSearchV1Response>
</soap:Body>
</soap:Envelope>
Introduction
Obviously, documentation is missing here. Unfortunately,
$soapClient->__getTypes()doesn’t tell much. It only shows available complex types supported by a web service, but it doesn’t show us the relationship among them. Even if You have a list of all available operations with their input and output types returned by$soapClient->__getFunctions(), there is no guarantee You can proceed without knowing the exact nature of the complex types or without having any kind of documentation. But fortunately, this is a SOAP-based web service that provides a WSDL document. The WSDL document describes all the supported operations and complex types, as well as their relationships. So, we can figure out how to use the service by only examining the WSDL document.There are two ways of examining the WSDL document:
1. Artifacts
The artifacts can be generated by tools provided by the strong typed languages like Java or C#. The https://qa-api.ukmail.com/Services/UKMAuthenticationServices/ page suggests to use the
svcutil.exetool to generate the artifacts for the C# programming language, or You can also use thewsimporttool to generate the artifacts for the Java programming language. I doubt that there can be any good tool for generating the artifacts for the PHP programming language.2. WSDL document and XML Schemas
If You’re not familiar with C# or Java, You can always examine the WSDL document by looking through it and the XML Schemas. The XML Schemas can be included in the WSDL document or imported from an external file. While the WSDL document describes the operations that can be performed on the web service, the XML Schemas describe the complex types and their relationships.
Action
I wrote the Introduction part so that You know how to do it on Your own. Below I want to show an example of it. For the purpose of examining the WSDL document I used both ways. First I generated the artifacts using the
wsimporttool, then I read a lot of XML.The WSDL document for this service is divided into several files using
importstatements. So, in order to find all the operations and complex types You have to follow theimportstatements.Authentication
If We look at the Authentication Service’s WSDL document (location), We can see that it imports another WSDL document:
The latter (location), in its turn, imports another one:
The final one (location), imports all the related XML Schemas:
It also describes the operations which can also be viewed by calling
$soapClient->__getFunctions():Here, We see that the
Login()operation accepts$parametersof typeLoginas its argument and returns a response of typeLoginResponse. This is how it looks in the WSDL document:Loginis a complex type, this can be seen in one of the imported XML Schema documents (schemaLocation):It has an element named
loginWebRequestwhich is also a complex type calledLoginWebRequestwhich is described in another imported XML Schema:LoginWebRequestis simpler. It has two simple typesUsernameandPasswordof typeString.In PHP complex types are represented by objects of
stdClass. So, in order to call theLogin()operation, We have to create two objectsLoginandLoginWebRequest:This gives us a result of type
LoginResponse:, which contains an element named
LoginResultwhich has a type ofUKMLoginResponse:UKMLoginResponsehas two elements of its ownAccountsof typeArrayOfAccountWebModelandAuthenticationTokenof typeStringand three more elements inhereted fromUKMWebResponse(note theextensionstatement)Errorsof typeArrayOfUKMWebError,Warningsof typeArrayOfUKMWebWarningandResultof typeUKMResultState:In the artifacts generated by the
wsimporttool it looks like this:So, in order to get the authentication token from the
LoginResponse, we do the following:Calling a method
I won’t be very specific here, because it’s very similar to what we did above.
As an example, let’s call a
AddDomesticConsignment()method. According to the WSDL document of the Consignment Service and the result returned by$soapClient->__getFunctions()theAddDomesticConsignment()method takes one$parametersargument of typeAddDomesticConsignmentand returns a result of typeAddDomesticConsignmentResponse. By analyzing theAddDomesticConsignmentcomplex type, we see that it has an element namedrequestof typeAddDomesticConsignmentWebRequestwhich extendsAddConsignmentWebRequestwhich itself extendsWebRequest. Following is the list of all of the elements of theAddDomesticConsignmentWebRequesttype:Note that not all of the elements are required. Those which are optional have the
minOccursattribute set to0in the XML Schema.So, eventually this is how We call the method:
The
AddDomesticConsignmentResponseis parsed as We parsed theLoginResponseaccording to its definition in the XML Schema document.Well, I guess this is all to it. I didn’t try it myself, but in theory it should work.
Hope this helps.
UPDATE
According to the documentation tracking the consignment should be as easy as doing the following:
That’s it!