Sending Parcels Through DHL API


At the time we in, 7th of August 2017, I already completed DHL API integration for a start-up company named Shippn to maximize correct and quick parcel sending at the software level.  At first glimpse it is a bit harsh to delve into tons of pages of DHL API but at the end I put the right pieces to the puzzle and my first hesitations on the works left its place to more satisfactory feelings. It was done!

Well, as I said, this article a bit showing off glimpse of the API at the August of 2017 which really changes fast, gets updated with new features. For instance, now, there isn’t any billing API for the parcels sent or labelled.

The maın features of the dhl apı

  • Capability handling for getting local and global product codes
  • Tracking handler for tracking the package extensively
  • Labeling handler for printing the AWB. Yes, indeed, API responses a PDF file byte data!
  • And at last arranging pick ups.

I will give code samples and we will be examining through through these samples. Codes pieces are only and only Python language I will be using Mini-DOM XML parser to parse the main files were taken from the DHL-PI and also Requests module to make HTTP requests easily…


DHL labelıng utılıty

We have been using as team, the Tornado, a Python HTTP framework and for simple post request the code below goes. What-ever you like to add to this request, it is at the end your call… For instance you can add order IDs.

Requirements to run the code below:

  • Put your DHL non-dutiable file under DHL folder and then name it NONDUTIABLE_REQ.xml
  • Create a folder named DHL_API/AWB_NOs/ to save the AWB pdfs.

How to fıll down the rıght sıde of the assıgnments

Well, it depends! Please, other than the advises here, follow the DHL documents. I will be trying at my best to help you!

  1. WeightUnit: “K” for kilograms and “L” for lbs.
  2. RequestedPickupTime: It is self-explanatory. If you already requested a pick up time please fill “Y” or put “N”…
  3. ShippingPaymentType: If shopper is going to pay, please put “S”, if recipient in duty please put “R” and if it is third party put “T”.
  4. What about local and global product codes? Please get them via Capability Handler.
  5. Note that the URL: is for testing. You can replace with the actual URL denoted in the DHL-PI.
  6. The major point of whole process above is to generously fetch the airway bill number. It can be used to track the package and also getting the PDF excerpt.

Possıble errors

  • Be sure that date are always stated some while time after the time we in, not so close not so far.
  • You may get permission denied error while writing the excerpt to file system. So bear in mind that you can always use “sudo chown -R user_name .” to make it writable.
  • Do not use as weight units, more than one character.
  • Bear in mind that Pythonic way of getting or reading files at the server level… It is always better to use with absolute path.

download the awb pdf from the tornado server

One way or another, downloading files from python servers are similar. I will be showing the method one more here:


I showed main method to reserve and send parcels and take the PDF response to attach your future parcels via Python Tornado HTTP Web Server. I would be glad if it dropped a little burden on your shoulders. Any comment or share will be appreciated. I will be continuing this article series with pick up handling and tracking.

Happy Coding!

About the author

Anil Bektas

Reader/Writer. Founder of Diary of Coders.

By Anil Bektas


Recent Posts

Recent Comments



Anil Bektas

Reader/Writer. Founder of Diary of Coders.

Get in touch

Links to my social media accounts. Thank you for following!

Tag Cloud