问题
I am struggling to access the mirth connect Rest api endpoints from a source javascript transformer of a mirth connect channel. My goal is to be able to export and import channel groups using javascript code in the transformer. I am aware that it is not possible to use XHR as it is specific to web browsers. I have tried searching for any good documentation on how to consume mirth connect rest api but I haven't been lucky either. Can someone please demonstrate maybe through code on how to export a mirth connect channel group using the mirth connect rest api in a Javascript transformer ? I must also admit that I am new to both mirth connect and rest api.
回答1:
The Mirth REST API is documented in the application itself using Swagger.
Navigate to https://your.mc.server:8443/api/
This is Swagger documentation for the entire API. Enter your admin user credentials in the header bar and it will let you make sample requests right from the documentation page.
Calling the API from MC is then done like any other HTTP service.
Using the API from MC itself is a LOT easier in version 3.5.0. Version 3.5.0 added BASIC authentication support . Versions prior to 3.5.0 required a session cookie, this prevents redundant logins since you can just pass session token but it requires a little more development to authenticate and get the cookie then do the login.
As far as MC is concerned, you're calling yet another REST API. The typical way to do this would be to kick off your process with whatever source connector you need. Then have a destination that calls the MC REST API. This destination is an HTTP sender like any other REST API endpoint. Use the response transformer on that destination to map the values you need from the response to your channelMap. Then do what you need to do. I would encourage you to look at the logical flow of your channel and consider this approach. Its how MC is meant to be used. This is described in more detail in a forum thread.
If you need to call the REST API from Javascript that is possible. I haven't done this personally but I have seen examples on the Mirth forums. The gist of the solution is that MC's Javscript is using Rhino which gives you access to the Java library for the Apache HTTPClient.
来源:https://stackoverflow.com/questions/47028857/access-mirth-connect-rest-api-from-javascript-transformers-mirth-3-5-1