faoc
faoc

Reputation: 385

Mirth Connect : Import Code Templates by REST API

i'm getting an error every time that i try to import codeTemplates using the service 'POST /codeTemplateLibraries/_bulkUpdate'.

I'm using a node client to send it:

const options = {
method: 'POST',
url: `...`,
headers:
{
'content-type': 'multipart/form-data',
Cookie: this.cookie
},
multipart: {
chunked: true,
data: [
{
'Content-Disposition': "form-data; name='libraries'",
'Content-Type': 'application/xml',
body: `<list>${xmlSetCodeLibs}</list>`
}
,
{
'Content-Disposition': "form-data; name='updatedCodeTemplates'",
'Content-Type': 'application/xml',
body: `<list>${xmlSetCodeTemplates}</list>`
}
]
}
};

Also i tryed, a PUT /codeTemplateLibraries but the result is not what i'm expecting. I receive http status 200 and libraries are inserted, but not the codeTemplates

Upvotes: 0

Views: 967

Answers (1)

SE Does Not Like Dissent
SE Does Not Like Dissent

Reputation: 1835

Having stumbled across the solution myself, I can answer the solution is counter-intuitive at best.

When copying a codeTemplateLibrary (not to be confused with a codeTemplate), Mirth updates both the codeTemplateLibrary and the codeTemplates, but the codeTemplates are not visible. In order to make them visible (and fix the bug), you must then, after doing a full update on the codeTemplateLibrary, update every codeTemplate individually, using the PUT /codeTemplates/{codeTemplateId} call.

So your code solution should:

  1. Call down the complete codeTemplateLibraries (be sure to send the header indicating you want the codeTemplate code included as well, as it's omitted by default)
  2. Push the codeTemplateLibraries to whichever Mirth instance you want
  3. Use E4X or a similar XML parsing tool to extract each codeTemplate instance found within your codeTemplateLibraries you called down earlier (you don't need to know which codeTemplate is under what codeTemplateLibrary as that data has been already been sent).
  4. Extract the codeTemplate ID (using E4X or similar)
  5. Using the ID you extracted, call PUT /codeTemplates/{codeTemplateId} (replacing {codeTemplateId} with the ID you extracted) which issues an 'update' to the now added codeTemplate (so you'll need to include the full code again) for each individual occurrence of codeTemplate found within the codeTemplateLibraries list that you have. This will make that specific codeTemplate visible.

What you should find after doing steps 4 to 5 for every codeTemplate instance is that the codeTemplate is now visible in Mirth. Yes it is inefficient and slow, but at present it's the only method I've managed to get working.

Upvotes: 1

Related Questions