Blog

    Mirth Connect REST API Gotchas in Channel Deployment Automation

    By GauravAugust 17, 20269 mins read
    On this page

    Mirth Connect REST API gotchas tend to appear the first time a team moves channel deployment automation into CI. A channel is not live because a file landed in git. NextGen's Client API expects a login, a PUT of the channel as XML, then a POST to _deploy, and the JSON samples on the OpenAPI page are not the payload most routes accept.

    Written for digital health founders and hospital CTOs whose interface teams want repeatable deploys, it covers the call sequence, the checks CI runs before and after the PUT, and rollback.

    What are the Mirth Connect REST API gotchas in channel deployment?

    The main Mirth Connect REST API gotchas in channel deployment are that most routes expect XML rather than the JSON in the samples, that a PUT stores a channel without running it, and that _deploy can return cleanly on a disabled channel. Agnotic Technologies scripts login, PUT with override, _deploy and a status read as one job.

    Automating Connect channel deploys?

    We export XML, PUT it with override, then POST _deploy. Tests stay a separate gate.

    Public NextGen Connect discussions document channel deploy as a login, then PUT of channel XML to /api/channels/{channelId}?override=true, then POST to /api/channels/{channelId}/_deploy. Most Client API routes expect application/xml.

    • Login: POST /api/users/_login. Hold the session. Do not embed the password in the channel XML.
    • Update: PUT /api/channels/{channelId}?override=true with Content-Type application/xml.
    • Deploy: POST /api/channels/{channelId}/_deploy. A disabled channel can return no error. Check enabled first.
    • Verify: read the channel status afterwards. The HTTP status of _deploy is not proof that traffic is flowing.

    Run the channel test suite before any of these calls. The deploy job assumes the XML it receives has already passed those tests, and it only moves that XML onto the engine.

    Why does channel deployment automation matter now?

    Channel deployment automation matters because a hospital interface estate grows faster than anyone can export and import channels by hand. Each manual step is a chance to ship the wrong revision, overwrite an emergency fix, or leave a channel stopped after a change.

    What must CI refuse to PUT?

    CI must refuse XML that still holds environment host names, secrets, or a disabled flag. Agnotic keeps those values in the destination's configuration map, not in the committed file.

    • Refuse: passwords, production URLs, and site identifiers in the XML.
    • Refuse: a channel whose enabled flag is false. _deploy on a disabled channel can look like success.
    • Keep: the channel id that git and the engine already share.

    Which Client API calls does a deploy job need?

    A deploy job needs four calls: log in, PUT the channel, POST _deploy, and log out. Anything more, such as reading the channel's status, is a check the job adds around those four.

    NextGen states that the Mirth Connect Administrator and the Command Line Interface both use one REST API to talk to the server, that teams can use the same API for their own integrations, and that it is documented on the server at /api.

    • Step 1, open a session: POST /api/users/_login as the deploy user, and keep the JSESSIONID cookie for the rest of the job.
    • Step 2, store the channel: PUT the XML with override=true. The engine now holds the new definition but still runs the old one.
    • Step 3, run it: POST _deploy for that channel id. This is the moment live traffic starts using the new code.
    • Step 4, close the session: POST /api/users/_logout with the same cookie, even when an earlier step failed.

    Open the Client API page on your own server before you script anything. Its operation list is the contract for that engine version, and routes can change between releases.

    How should CI authenticate to the Connect engine?

    CI should sign in as its own Connect user, open one session per job, and close it at the end. The default admin account and a shared human login are both wrong for a pipeline.

    Mirth Connect supports session cookie authentication and basic authentication. NextGen prefers the session: POST /users/_login, send the returned JSESSIONID cookie on each call, then POST /users/_logout with the same cookie.

    • Account: a named deploy user, so the engine's event log shows that the pipeline, not a person, made the change.
    • Secret: the password sits in the CI secret store and reaches the job as a masked variable.
    • Transport: HTTPS to the engine's API port. Install a real certificate on the engine instead of switching off verification in the script.
    • Logout: run it in a finally block, so an aborted job does not leave an open session behind.

    What does override=true replace on the engine?

    override=true replaces the stored channel even when the engine holds a different revision from the one in your XML. That is what automation needs, and it is risky when someone has edited the channel by hand in the Administrator.

    Without the flag, the engine can refuse the write when revisions differ. With it, your copy wins and the hand edit is gone. Agnotic keeps the flag, because CI needs a predictable write, and moves the safety check to the step before the PUT.

    A pipeline that cannot see hand edits will sooner or later overwrite an emergency fix someone made in the Administrator during an incident. The comparison below is what catches it.

    What should CI compare before it sends the PUT?

    CI should read the channel currently on the engine and compare it with the copy recorded at the last successful deploy. If they differ, someone changed production outside the pipeline, and the job stops for a person.

    • Channel id: the id inside the XML must match the id in the URL. A mismatch is a packaging error, not a deploy.
    • Revision: the engine's revision should equal the revision the pipeline wrote down last time.
    • Drift: any other difference is a hand edit. Export it to a branch before anything overwrites it.
    • Missing: a channel that does not exist on the target yet is a first install and needs its own approval.

    How do you confirm that _deploy actually worked?

    You confirm it by reading the channel's state after the call, not by trusting the HTTP status. A deploy can return without error while the channel stays stopped, because its initial state is Stopped or because it is disabled.

    • State: read the channel's status and expect Started, unless the change request said otherwise.
    • Revision: the deployed revision should match the one the job just stored.
    • Errors: check the server event log for deploy-time failures, such as a deploy script that threw.
    • Traffic: for a listener, watch the next real inbound message reach the first destination.

    If the status read shows Stopped or the wrong revision, the job fails and alerts the platform engineer. It does not call _deploy again in a loop, because a second deploy of a broken channel tells you nothing new.

    Which objects does a channel PUT leave untouched?

    A channel PUT carries the channel only. Code template libraries, the configuration map, library resources, global scripts and alerts are separate objects on the engine, and a job that ignores them ships half a change.

    • Code templates: if the channel calls a function that changed, the library has to reach the engine first.
    • Configuration map: a new key that the channel reads must exist on the target before _deploy.
    • Library resources: a channel linked to a resource the target lacks fails at deploy or on its first message.
    • Dependencies: Connect lets a channel name other channels that must deploy and start before it. Deploy in that order.

    Agnotic runs these as earlier stages of the same job: libraries first, then configuration keys, then the channel. Each stage has its own check, so a failure points at one object instead of the whole release.

    A worked example: promoting one ADT channel to production

    A worked example: a hospital's ADT routing channel has passed its tests in staging, and the change adds a destination for a bed-board system. The pipeline holds the exported XML and the list of configuration keys the new destination reads.

    • Step 1, the job checks that the bed-board host key exists in the production configuration map.
    • Step 2, it logs in as the deploy user and reads the live channel. The revision matches the last recorded deploy, so there is no drift.
    • Step 3, it PUTs the XML with override=true, then POSTs _deploy.
    • Step 4, it reads the status, finds the channel Started at the new revision, and logs out.

    The bed-board team then confirms the next real admission appeared on their screen. The change request closes with the commit hash and the new revision on it.

    What should the pipeline record for every deploy?

    The pipeline should record who deployed what, to which engine, and with what result, in a form an auditor can read later. The engine's own event log is one half of that trail, and the CI record is the other.

    • Change: commit hash, channel id and channel name.
    • Engine: target server, revision before and revision after.
    • Result: the _deploy response and the status read that followed it.
    • Never: the password, the session cookie or a sample message body.

    How do you roll back a bad channel deploy?

    You roll back by deploying the previous XML from git through the same four calls. A rollback is a normal deploy of an older commit, so it gets the same drift check and the same record.

    A rollback does not undo messages the bad version already processed. List the message ids received between the two deploys and decide with the receiving team whether any need reprocessing.

    If the new version cannot start at all, undeploy it rather than leave a broken definition in place, then deploy the last good copy.

    What are the common mistakes with Mirth Connect deploy automation?

    The common mistakes come from treating the Client API like a generic JSON service and the HTTP status like proof of a live channel. Each one below has caused a silent failure on a real engine.

    • Posting the JSON model from the OpenAPI page instead of the channel XML the route expects.
    • Treating a successful PUT as a deploy, so the engine stores the new code but keeps running the old one.
    • Deploying as the default admin user, which hides the pipeline's changes among human edits in the event log.
    • Shipping a channel before the code template library or configuration key it depends on.
    • Skipping the drift check, so an emergency hand edit made during an incident is overwritten without anyone noticing.

    Who owns each part of a channel deploy?

    The interface team owns the XML and the decision to ship it. The platform team owns the pipeline, the deploy user and the engine. The receiving system's team owns the confirmation that traffic arrived.

    • Interface engineer: the channel change, its tests and the configuration keys it needs.
    • Platform engineer: the CI job, its secrets, the engine certificate and the drift check.
    • Receiving team: confirmation that messages reached their system after the deploy.
    • Change approver: the go or no-go when the drift check stops a job.

    How does Agnotic run the deploy?

    Agnotic builds the deploy job for the client's engines: it exports XML from the engine that passed tests, checks for drift, PUTs the channel, POSTs _deploy and reads the status before the change closes. The client keeps the job, the deploy user and a written runbook.

    XML in, then _deploy

    Login, PUT with override, POST _deploy. Environment values stay out of git.

    Related reading on Agnotic

    Tests before deploy, managing channels, and outbound HTTP calls from a channel.

    Sources

    Frequently Asked Questions

    Most Client API routes expect XML. NextGen has said the JSON model in Swagger is not the payload.

    Talk to an engineer about your project

    Send the channel XML you want live. We will PUT it with override, POST _deploy, and keep site secrets out of git.