Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi espero,

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:
1. get a shipment request with address, etc. from your existing web system.
2. translate that data into a Perl data structure containing all of the elements that DHL will need for a valid shipping request.
3. encode that Perl Data Structure into JSON
4. send JSON formatted request to DHL
5. see what DHL has to say about that request (decode their JSON formatted response).

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.


In reply to Re^3: DHL API Integration by Marshall
in thread DHL API Integration by espero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-02-02 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (16 votes). Check out past polls.

    Notices?