Alexander
Alexander

Reputation: 139

Download Proof of Delivery as PDF in UPS API

UPS provided DeveloperKit to find delivery status. Below is an example for .Net:

TrackService track = new TrackService();
                TrackRequest tr = new TrackRequest();
                UPSSecurity upss = new UPSSecurity();
                UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
                upssSvcAccessToken.AccessLicenseNumber = "Your access license number";
                upss.ServiceAccessToken = upssSvcAccessToken;
                UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
                upssUsrNameToken.Username = "Your username";
                upssUsrNameToken.Password = "Your password";
                upss.UsernameToken = upssUsrNameToken;
                track.UPSSecurityValue = upss;
                RequestType request = new RequestType();
                String[] requestOption = { "15" };
                request.RequestOption = requestOption;
                tr.Request = request;
                tr.InquiryNumber = "Your track inquiry number";
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11; //This line will ensure the latest security protocol for consuming the web service call.
                TrackResponse trackResponse = track.ProcessTrack(tr);

                //ResponseType loResponse = trackResponse.Response;
                Console.WriteLine("The transaction was a " + trackResponse.Response.ResponseStatus.Description);
                Console.WriteLine("Shipment Service " + trackResponse.Shipment[0].Service.Description);
                Console.ReadKey();

This code works fine, and returns shipment details as text. I need to download Proof of Delivery (POD) as PDF.

The manual shows that loading such PDF is possible via object /TrackResponse/Shipment/Document/Content.

However, the object Document is not available under trackResponse.Shipment. Response option 15 used in the request means that Signature Tracking only is ON.

Any ideas how to get the Proof of Delivery as a PDF file?

Upvotes: 0

Views: 1632

Answers (1)

Alexander
Alexander

Reputation: 139

UPS sends Proof of Delivery (POD) in HTML format only. Conversion to PDF needs to be done by the developer.

HTML code comes in: trackResponse.Shipment[0].Package[0].Activity[0].Document[0].Content

That value needs to be decoded:

byte[] data = Convert.FromBase64String(trackResponse.Shipment[0].Package[0].Activity[0].Document[0].Content);  
string decodedString = Encoding.UTF8.GetString(data);  

Then decoded string needs to be converted to PDF. I used a third-party library, available through NuGet.

Upvotes: 1

Related Questions