Announcement

Collapse
No announcement yet.

REST API for code templates and libraries

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

  • REST API for code templates and libraries

    I'm having trouble with Mirth's REST API for importing code templates and libraries.

    For other config options, it was quick and easy to make use of these:

    PUT users/{userId}/preferences
    PUT server/configuration
    PUT server/settings

    But has anyone been able to get the following REST API endpoints to work?

    PUT /codeTemplateLibraries
    POST /codeTemplateLibraries/_bulkUpdate
    PUT /codeTemplates/{codeTemplateId}

    For example, here's a simple test of importing a code template library:

    GET /codeTemplateLibraries returns:

    Code:
    <list>
        <codeTemplateLibrary version="3.4.1">
            <id>75b7305a-72b2-40d3-b374-cd272def2f83</id>
            <name>Library 1</name>
            <revision>2</revision>
            <lastModified>
                <time>1470077306242</time>
                <timezone>America/Chicago</timezone>
            </lastModified>
            <description>Test 1</description>
            <includeNewChannels>true</includeNewChannels>
            <enabledChannelIds/>
            <disabledChannelIds/>
            <codeTemplates/>
        </codeTemplateLibrary>
    </list>
    If I use this XML for a PUT /codeTemplateLibraries (either from the web UI or from our internal .NET project) I get back the error "HTTP ERROR: 500 - Problem accessing /api/codeTemplateLibraries. Reason: Request failed."

    If I modify the XML to match the model schema in the web UI, I get:

    Code:
    <list>
        <codeTemplateLibrary version="3.4.1">
            <id>75b7305a-72b2-40d3-b374-cd272def2f83</id>
            <name>Library 1</name>
            <revision>2</revision>
            <lastModified>2016-08-01T16:49:38.778Z</lastModified>
            <description>Test 1</description>
            <includeNewChannels>true</includeNewChannels>
            <enabledChannelIds/>
            <disabledChannelIds/>
            <codeTemplates/>
            <purgedProperties/>
        </codeTemplateLibrary>
    </list>
    But this also results in the same error. I've spent a lot of time trying different things to get the code templates and libraries to import, as well as many Google and forum searches, but I'm not having any luck on this.

    In the past we've used Mirth's CLI to import these, but we're trying to move everything to the REST API. It's a great API that'll make our lives much easier once we get everything worked out.

    Does anyone have any ideas or XML templates that work?

    Thanks!

  • #2
    I should add that I'm using the latest version of Mirth Connect, v3.4.1.8057.

    Comment


    • #3
      I’m running into the same issue. I tried using the output of GET /codeTemplateLibraries (with includeCodeTemplates set to TRUE) as the input for PUT /codeTemplateLibraries, but it returns an Error 500.

      In comparing the output from the GET to the Model Schema of the PUT, it looks like the GET isn't returning everything. The schema wants items like addToScripts, functionDefinition, purgedProperties, and others that GET doesn't provide. I added these in as empty tags as best I could, but I'm still getting the error.

      I tested this on v3.4.1.8057 (evaluating it before migrating from v3.3.1).

      Could this be a bug?

      Comment


      • #4
        brathouz, were you able to get PUT /codeTemplateLibraries to work? I'm still stuck. I didn't have any trouble with PUT server/configuration, though.

        Comment


        • #5
          No, I haven't been able to get it to work. I'd expect the output of GET /codeTemplateLibraries (or an export from the GUI) would work as the input for PUT /codeTemplateLibraries, but it doesn't. I've tried modifying the GET output to shoehorn it into the PUT input, but no such luck.

          Without having an example to work from, I can only assume this is broke.

          Comment


          • #6
            It's a bit inconsistent right now... the GET endpoint returns a List, but the PUT endpoint expects a set. If you change your XML to use <set> it should be fine.

            I've created an issue to make that more consistent: MIRTH-4039
            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.

            Comment


            • #7
              Hi all,

              I am stuck with these endpoints too. I want to add new code templates from my app everytime I create a new channel, but there is no way I can get it to work although I am already replacing <list> by <set>. I did get the PUT /codeTemplateLibraries endpoint to work (it actually creates the libraries even if they don't exist, just like a POST request, but it doesn't create the code templates they contain), but it doesn't work the same for the /codeTemplates one (this one just updates the existing code templates, very nicely though).

              Given this, what steps should I follow in order to create new code templates using your REST API? I also had some problems with the input format of the bulk_update endpoint, maybe that is the endpoint I should use for my purposes? By the way, I don't understand either why you are showing JSON examples in the docs when you are actually expecting XML.

              Thank you all for your great job and hope you can help me! :-)

              Comment


              • #8
                possible solution

                see this thread for a solution for the _bulkUpdate api
                http://www.mirthcorp.com/community/f...d=1#post259878

                Comment

                Working...
                X