Announcement

Collapse

Mirth Connect 4.1.0 Released!

Mirth Connect 4.1.0 is now available as an appliance update and on our GitHub page. Mirth Connect 4.1.0 includes new features such as new event log messages, additional fields to the Welcome to Mirth Connect screen, new information included in alerts as well as many smaller changes, updates, and improvements. This release also contains several improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Extract zip file from response from "HTTP Sender" GET method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extract zip file from response from "HTTP Sender" GET method

    Hi all,

    I have to extract a zip file from an API response.

    The description of the response is :
    The format of the HTTP response body is as follow if the status code is 2xx.
    i. Part 1 - header
    1. A Content-type header is “application/zip;charset=UTF-8”.
    2. A Content-disposition header that includes a patient ID and the exact setup time of the corresponding measurement and the format of the corresponded file name is
    “{PatientID}_{YYYYMMDDHHmm}_{reportTypeName}.zip”;
    an example is as below:
    attachment; filename="P001_201804270937_cardiac.zip";
    filename*=utf-8''P001_201804270937.zip


    i. Part 2 - A report file was encoded Base64 format (my zip file).

    I have an HTTP SENDER (GET Method) and I receive a correct response with status 2xx.

    In the 'Response Transformer', I get the response with : "var myReponse = response.getMessage();"

    My (big) problem is : how could I extract the base64 data from my response ?

    The responseHeader is :
    {vary=[Accept-Encoding],
    connection=[keep-alive],
    transfer-encoding=[chunked],
    content-type=[application/json;charset=UTF-8],
    date=[Tue, 26 Jul 2022 09:19:48 GMT],
    keep-alive=[timeout=120],
    content-disposition=
    [attachment; filename="16679585_202204251357-cardiac.zip"; filename*=utf-8''16679585_202204251357-cardiac.zip],
    cache-control=[no-store],
    server=[nginx]}

    How can I separate Header from Body of my response ? Any idee ?

    Thank's.

  • #2
    Interesting.

    In the response transformer, what does msg variable holds.?
    Typically, msg holds the ACK or response coming from the destination. In an HL7 destination it holds the ACK.

    I am guessing in your case, it will hold the entire HTTP response.
    HL7v2.7 Certified Control Specialist!

    Comment


    • #3
      In other words, what siddharth is saying is that the zipped file is the reponse message (aka "body") content, you don't need to "seperate" it, it is already seperated.
      Diridium Technologies, Inc.
      https://diridium.com

      Comment


      • #4
        Thank you for yours responses!

        Effectively, "msg" contains my response (zip) and has the same value than "response.getMessage()".

        My problem now is just a problem of CHARSET : i can't unzip the file.
        When I unzip the file, I have an error : "Local : Descriptor UTF8 Descriptor_ERROR " :

        image.png

        When I do the same with Postman, all is OK ! I can unzip the file.

        I tried to convert to others charset (ISO-8859-x,...) without success!
        In UTF-8 to.

        Any idee ?

        Thank's.

        Comment


        • #5
          Can you share the documentation for the API you are calling?
          Diridium Technologies, Inc.
          https://diridium.com

          Comment


          • #6
            I don't remember but I think there is an option to select the charset in the HTTP Sender connector.
            HL7v2.7 Certified Control Specialist!

            Comment


            • #7
              Here is the doc. for the API.
              In the doc, it's the API005.
              In my channel, API001 & API004 are good.

              I'm working in Mirth 4.0.1 on Linux. But my environment is Windows.
              Charset UTF-8 on Linux is it the same than Windows ? (maybe a stupid question?)

              Here a printscreen of my destination : URL is : "https://apieu.rooticare.com/api/rooticare/institutions/eu121/reports/id_of_my_hospital/file"

              image.png

              To Siddhart, i use content-type "application/json;charset=UTF-8"

              Thank you!
              Attached Files

              Comment


              • #8
                I've forgot to say that the response of the API is passed to a destination "FileWriter" with method "smb" and the encoding is UTF-8.

                Comment


                • #9
                  The document says

                  HTTP Media type (content-type): application/x-www-form-urlencoded for calling the API005.


                  HL7v2.7 Certified Control Specialist!

                  Comment


                  • #10
                    You might want to install HTTP traffic monitors, to see if your outgoing request from Mirth is same as what Postman is sending, since as you told it works from Postman.
                    https://stackoverflow.com/questions/...nd-for-windows
                    HL7v2.7 Certified Control Specialist!

                    Comment


                    • #11
                      eh, just set up an echo server. those tools on the stackoverflow post are a bit overkill.

                      If you have a recent version of node/npx:

                      npx http-echo-server

                      that fires up a dumb listener on port 3000 that you can send to with mirth and postman.
                      Diridium Technologies, Inc.
                      https://diridium.com

                      Comment

                      Working...
                      X