Reputation: 4268
I have a php solution for ups tracking. The response which I get from UPS using the language "english" Is there an way to get another language for the response?
This is my code from the ups developer documentation: This is my code from the ups developer documentation: This is my code from the ups developer documentation: This is my code from the ups developer documentation:This is my code from the ups developer documentation:
// Configuration
$accessLicenseNumber = "xxx";
$userId = "xxx";
$password = "xxx";
$endpointurl = 'https://onlinetools.ups.com/ups.app/xml/Track';
try {
// Create AccessRequest XMl
$accessRequestXML = new SimpleXMLElement ( "<AccessRequest></AccessRequest>" );
$accessRequestXML->addChild ( "AccessLicenseNumber", $accessLicenseNumber );
$accessRequestXML->addChild ( "UserId", $userId );
$accessRequestXML->addChild ( "Password", $password );
// Create TrackRequest XMl
$trackRequestXML = new SimpleXMLElement ( "<TrackRequest></TrackRequest >" );
$request = $trackRequestXML->addChild ( 'Request' );
$request->addChild ( "RequestAction", "Track" );
$request->addChild ( "RequestOption", "activity" );
$trackRequestXML->addChild ( "TrackingNumber", "xxx" );
$requestXML = $accessRequestXML->asXML () . $trackRequestXML->asXML ();
$form = array (
'http' => array (
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $requestXML
)
);
// get request
$request = stream_context_create ( $form );
$browser = fopen ( $endpointurl, 'rb', false, $request );
if (! $browser) {
throw new Exception ( "Connection failed." );
}
// get response
$response = stream_get_contents ( $browser );
fclose ( $browser );
if ($response == false) {
throw new Exception ( "Bad data." );
} else {
// get response status
$resp = new SimpleXMLElement ( $response );
}
Header ( 'Content-type: text/xml' );
} catch ( Exception $ex ) {}
}
Upvotes: 0
Views: 2154
Reputation: 439
This is the example of a soap client from the development kit UPS
<?php
//Configuration
$access = " Add License Key Here";
$userid = " Add User Id Here";
$passwd = " Add Password Here";
$wsdl = " Add Wsdl File Here ";
$operation = "ProcessTrack";
$endpointurl = ' Add URL Here';
$outputFileName = "XOLTResult.xml";
function processTrack()
{
//create soap request
$req['RequestOption'] = '15';
$tref['CustomerContext'] = 'Add description here';
$req['TransactionReference'] = $tref;
$request['Request'] = $req;
$request['InquiryNumber'] = '';
$request['TrackingOption'] = '02';
echo "Request.......\n";
print_r($request);
echo "\n\n";
return $request;
}
try
{
$mode = array
(
'soap_version' => 'SOAP_1_1', // use soap 1.1 client
'trace' => 1
);
// initialize soap client
$client = new SoapClient($wsdl , $mode);
//set endpoint url
$client->__setLocation($endpointurl);
//create soap header
$usernameToken['Username'] = $userid;
$usernameToken['Password'] = $passwd;
$serviceAccessLicense['AccessLicenseNumber'] = $access;
$upss['UsernameToken'] = $usernameToken;
$upss['ServiceAccessToken'] = $serviceAccessLicense;
$header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
$client->__setSoapHeaders($header);
//get response
$resp = $client->__soapCall($operation ,array(processTrack()));
//get status
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
//save soap request and response to file
$fw = fopen($outputFileName , 'w');
fwrite($fw , "Request: \n" . $client->__getLastRequest() . "\n");
fwrite($fw , "Response: \n" . $client->__getLastResponse() . "\n");
fclose($fw);
}
catch(Exception $ex)
{
print_r ($ex);
}
?>
Upvotes: 0
Reputation: 439
You can not do this via XML, you need to use WSDL (SOAP) or JSON.
You can use the Local TAG in /TrackRequest/Locale
=> <v3:Locale>it_IT</v3:Locale>
WSDL (SOAP) Request
url for test webservices https://wwwcie.ups.com/webservices/Track
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0"
xmlns:v3="http://www.ups.com/XMLSchema/XOLTWS/Track/v2.0"
xmlns:v11="http://www.ups.com/XMLSchema/XOLTWS/Common/v1.0">
<soapenv:Header>
<v1:UPSSecurity>
<v1:UsernameToken>
<v1:Username>USERID</v1:Username>
<v1:Password>PASSWORD</v1:Password>
</v1:UsernameToken>
<v1:ServiceAccessToken>
<v1:AccessLicenseNumber>API KEY</v1:AccessLicenseNumber>
</v1:ServiceAccessToken>
</v1:UPSSecurity>
</soapenv:Header>
<soapenv:Body>
<v3:TrackRequest>
<v11:Request>
<v11:RequestOption>1</v11:RequestOption>
<v11:TransactionReference>
<v11:CustomerContext>Your Test Case Summary Description</v11:CustomerContext>
</v11:TransactionReference>
</v11:Request>
<v3:Locale>it_IT</v3:Locale>
<v3:InquiryNumber>TRACKING NUMBER</v3:InquiryNumber>
</v3:TrackRequest>
</soapenv:Body>
</soapenv:Envelope>
I did some tests using the Tracking Number of tests and with those it does not work.
I then used a true tracking code sent to my country (Italy) and it works
RESPONSE WSDL(SOAP)
..........
<trk:Status>
<trk:Type>M</trk:Type>
<trk:Description>Ordine elaborato: Pronto per UPS</trk:Description>
<trk:Code>MP</trk:Code>
</trk:Status>
..........
I used Postman to make requests
You can also use JSON (See the guide on the UPS website)
Upvotes: 0