|Don't ask to ask, just ask|
Re^3: DHL API Integrationby Marshall (Canon)
|on Mar 29, 2022 at 01:25 UTC||Need Help??|
Thanks for more info that put your application into context. I don't know what the Postman application is, nor have I made any serious study of the DHL JSON API. However, my understanding is that they have a test URL, where you can "practice" sending requests without actually triggering a shipment. It also appears to me that you just need a very small subset of the DHL API's capabilities. It also appears that there is really only one "user" for your application which will be a custom deal for your company (no need to bullet proof a complete turnkey application for some unknown person).
I recommend starting simple. Program #1: Get the address (and perhaps package weight? or whatever else you need) from your existing order system and print that to the screen. Program #2: Take output of prog #1 and format it into the JSON format needed by DHL, send it as a shipment request and see what you get back (perhaps at first just print their JSON response to the screen). Get the "good machine" case working. Then intentionally booger the address like maybe no postal code or whatever you can ad hock dream up - see how "well behaved" the DHL I/F is in actual practice with "bad" input. You will need to handle all error possibilities from the DHL spec, but at first just hack around and discover things by playing...The purpose being to gain experience with Perl and looking at JSON.
The DHL CPAN module mentioned earlier is likely to be a lot more trouble than it is worth to you. When I briefly looked at it, one of its main purposes was to process what are called Asynchronous Requests. Basically this allows you to have multiple outstanding requests at a time. If you do that, you can cram more requests per second into DHL at the cost of an order of magnitude of complexity. Do not do that. Send a single request, wait until DHL has processed that request and replied with "the answer". Then do the next request, etc. You do not describe a "high volume" application.
I don't think the YAML spec will be of much use either. That is basically a general data description language which does not tell you exactly the JSON format that DHL expects for that data. This "I have a Postman JSON collection file which contains sample requests for all of the DHL services and I was able to get a response form the server." sounds a lot more promising.
You will need to do the homework on what parts of the DHL API you need to implement (and I suspect this subset is tiny).
The Monks can help with refining your Perl code. This is best done by starting to write some code yourself. Then when you get into trouble or just want coding advice, post a runnable code example on SOPW. It doesn't have to be completely working - but should be enough so that a Monk can just click on it and run it themselves to replicate your error condition. "use warnings;" and "use strict;" and get rid of all syntax errors. And of sourse should have the dummy credentials and test URL that you are using.
This is a big "first Perl project". Start with one simple piece at a time. I would look at Perl JSON module, encoding and decoding a Perl data structure into JSON. If you have it JSON::XS is faster. XS typically means a completely compatible version written in C so that it runs faster. However, in your case, the data structures that you need to send and receive are "small" and this probably makes no significant difference.
Update: Now that I think about it, you say you have some properly formatted JSON examples. Start by using the JSON module to translate one of your examples into a Perl data structure. You can use Perl Data Dumper to see what kind of thing you have. Then write your own Perl code to access the created Perl structure and print each element yourself. To send JSON to DHL, you will have to reverse the process, create Perl Data Structure, then encode it.
Update2: So I guess basic workflow is like this:
As first steps, (1) figure out how to get the "triggering event" from the existing system. (2) work on sending and receiving the JSON formatted info between your app and DHL.
If you are successful with this first part, requirements will expand to potentially "solving global hunger level". Don't start with the idea of "solving world hunger". Start with making your shipping process incrementally better.