How to pass authentication parameters in REST API?

How can I pass the authentication parameters into the rest api call in openmrs?

One possible way is to use HTTPBasicAuthFilter:

1 Like

We send a request to the session rest resource with an authorization header in the format "basic : " + base64-encode(username + “:” + password). For an example using angular see (especially line61):


like @jdick said.

In general just send the request with header “Authorization” example:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
1 Like

I moved a post to a new topic: How to change UI styling of OpenMRS 2.2?

Thanks that worked! I sent it in Java using the following code:

String url="http://localhost:8081/openmrs-standalone/remotecommunication/postHl7.form";
URL object=new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
//adding the request headers
String encoding = DatatypeConverter.printBase64Binary("admin:Admin123".getBytes("UTF-8"));
con.setRequestProperty("Authorization: Basic ",encoding);

Hope this helps other newbies like me in the future !


1 Like

Thank you!

Thank you…!

I need to make REST API calls with an already authenticated session. E.g. if I develop my own mobile client for OpenMRS, where the physician logs in once and subsequently, the data is accessed using REST calls. In this case, what should I pass in place of base64 encoded credentials?

I’m not sure if am getting you well, are you asking how to pass in your login credentials to get authenticated or how to make subsequent calls upon successful login?

How to make subsequent calls post successful login? Because I won’t have the user name and password to pass in the REST call header, only the session id of a valid authenticated session.

You need to send the jsessonId on every subsequent call after login, but the thing is that you need to fetch it from the server after login as shown on this page under the authentication section

Am using AJAX and a fragment controller. Am experiencing a UI Session Authentication error. How would you do authentication in AJAX?

Here is my discussion: Find Patient by Fingerprint

@wyclif @lluismf

By the time you make the REST call, can you ensure that you are logged in the browser?

1 Like