web stats
Access Mirth REST API from external javascript code - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2017, 04:06 AM
Arash Arash is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 7
Arash is on a distinguished road
Default Access Mirth REST API from external javascript code

Hi,

I'm trying to access the Mirth REST API through external javascript code, more specifically a node js application. This is how a make a call:

Code:
var rest = require('restler');

rest.get('https://localhost:8443/api/channelgroups', {
  username: 'testuser',
  password: 'testpass'
}).on('complete', function(result) {
    console.log(result);
  }
});
The response gives me this message:
HTTP ERROR: 401
Problem accessing /api/channelgroups. Reason: Unauthorized

I've also tried using SOAPUI with Basic Authentication, but I receive the same error message. Does anyone know how to resolve this issue?

Thanks for your help!
Reply With Quote
  #2  
Old 11-25-2017, 03:24 AM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 137
odo is on a distinguished road
Default

If I remember right, you first have to authenticate and then send the session id with your call.
Reply With Quote
  #3  
Old 11-26-2017, 01:19 AM
Arash Arash is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 7
Arash is on a distinguished road
Default

Thanks for helping out odo!

Do u know perhaps how this authentication call looks like? Cant seem to find a login in the REST Api.

Cheers,
Arash
Reply With Quote
  #4  
Old 11-27-2017, 05:27 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 275
AlexNeiva is on a distinguished road
Default

Hello,

as @odo mentioned, yes, you need to first call the login method, get the Cookie with key JSESSIONID, and then when you call any other method, you need to send in the same Cookie (ex: JSESSIONID=abcdef123) that you got from login.

Best Regards
Reply With Quote
  #5  
Old 11-27-2017, 06:05 AM
Arash Arash is offline
Mirth Newb
 
Join Date: Sep 2017
Posts: 7
Arash is on a distinguished road
Default

Excellent! Works like a charm

Thank you both!

Cheers,
A
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:33 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation