No announcement yet.

How to handle an ACK from an HTTP POST using the HTTP Sender?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to handle an ACK from an HTTP POST using the HTTP Sender?


    I've searched the forums and have not figured out what I need. I want to POST an HL7v2 message as a string using the HTTP Sender. (i.e. as a simple form field. Not a SOAP request or anything like that.) What should be the response of this POST in case there's an error or in case it is successful? When sending via MLLP the MLLP listener can respond with an ACK, but I'm not sure exactly what the response to an HTTP POST should look like?

    Based on reading other posts to the forums it seems Mirth would need to use a "response transformer". Is this correct? Does this mean the response could be e.g. just an HL7v2 ACK message in the body of the HTTP response? Is there a convention or best practice for this sort of thing?


  • #2
    Since you've cross-posted on both here and SO, I'll just copy my answer from there.

    The short answer is that it's completely up to you... Mirth Connect can accommodate any response (or lack thereof) and perform custom user-logic to decide whether the response is "successful" or not.

    You could have your external web service generate an HL7 v2.x ACK and send that back. Then on the HTTP Sender side, make sure your Response data types are set to HL7 v2.x, and enable "Validate Response" in the destination settings.

    You can also have your web service generate a completely custom response and do custom validation on the MC side. For example if you have your web service send back a response like this:

        "success": true,
        "message": "Message received successfully."
    Then you can set your Response data types to JSON, and do this in the response transformer:

    if (msg.success !== true) {
        responseStatus = ERROR;
    responseStatusMessage = msg.message;
    You can also validate purely on the response status code. By default with an HTTP Sender, the message status will be set to SENT only if the HTTP request returned with a status of < 400. Anything else and the status will be left as QUEUED (or ERROR if queuing is disabled).

    You can override that behavior in the response transformer though. Maybe you only want it to be SENT if the status is specifically 200 (and not other 2xx or 3xx codes). Set your Response data types to Raw (so that the response transformer will execute even when there is no response), and do this in the response transformer:

    var responseStatusLine = $('responseStatusLine');
    var responseCode = parseInt(responseStatusLine.split(' ')[1], 10);
    if (responseCode != 200) {
        responseStatus = ERROR;
        responseStatusMessage = responseStatusLine.substr(responseStatusLine.indexOf(' ')).trim();
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

    - How do I foo?
    - You just bar.


    • #3
      Mirth response

      I am using mirth to sent data in some API. I have successfully send data to the API and also get response. As above you have mentioned code for to get response but I got stuck where to put these code either in destination transformer or in source transformer. I also want to store this response in my local system.
      Hemant Gupta