NOTE: This api wrapper is not totally complete with all of Mirth's REST api calls. If you have a request for a specific api call, please make an issue on GitHub.
{
"instanceName": "{instance IP or DNS Name}",
"credentials": {
"username": "{username}",
"password": "{password}"
}
}
alternatively you can provide the mirth instance (ip or domain name) and user/pass combo
service = MirthService(username="{username}", password="{password}", instance="{mirthInstance}")
Usage
importjsonimportmirthpyimporturllib3urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) #to supress ssl warningconfig=json.load(open('config.json'))
service=MirthService(config)
service.open() # to login and initialize any service variables# Get channel namesnamesAndIds=service.getChannelIdsAndNames()
forniinnamesAndIds.entry:
print(f"{ni.string[1]} - {ni.string[0]}") # channelName - channelId# Get Id by nameid=service.getChannelIdByName('Test Channel')
channel=service.getChannel(id)
print(channel.name)
print(channel.description)
print(channel.sourceConnector.transformer)
iftype(channel.sourceConnector.properties) ==JavaScriptReceiverProperties:
# do stuff we'd know only a javascript reader would havescript=channel.sourceConnector.properties.script# Get multiple channelschannelIds= ["44dacc20-718a-490c-bfcf-82355ed9209d", "3bb08639-7725-4b1b-a2ac-13687101fe9b"]
c=service.getChannels(channelIds)
forchannelinc.channels: print(channel.name)
# Get all channelschannels=service.getChannels()
forchannelinchannels.channels:
print(f"{channel.name} - {channel.description}")
# get all enabled channelsenabledChannels= [channelforchannelinchannels.channelsifchannel.exportData.metadata.enabled=='true']
# get only javascript readersjReaders= [channelforchannelinenabledChannelsiftype(channel.sourceConnector.properties) ==JavaScriptReceiverProperties]
# get certain code templatescodeTemplates=service.getCodeTemplates(['0d42f17b-54a4-40c1-8e7b-b43c3eb1b433', '37139e86-88db-41fa-bf80-8c08456caa10'])
forctincodeTemplates.codeTemplates:
print(f"{ct.name} - {ct.id}")
# get all code templatescodeTemplates=service.getCodeTemplates()
forctincodeTemplates.codeTemplates:
print(f"{ct.name} - {ct.id}")
code=ct.properties.find('code').textservice.close() # to log out and close any service related objects
Supported Mirth API Calls
Server
Mirth API Route
mirthpy method
Description
GET /server/version
service.getVersion()
Gets Mirth Instance version
POST /server/_generateGUID
service.getGUID()
Gets Mirth specific GUID for ids
GET /server/time
service.getTime()
Gets current Mirth Server time
GET /server/channelTags
service.getTags()
Gets all tags
GET /server/configurationMap
service.getConfigurationMaps()
Gets all configuration mappings
Events
Mirth API Route
mirthpy method
Description
/events
service.getEvents(jsonParams)
Gets mirth events, can specify what parameters to pass
Channel
Mirth API Route
mirthpy method
Description
POST /channels
service.createChannel(channel)
Creates a channel in mirth instance based on channel object