dsurrao
(Dominic Surrao)
1
I first authenticate against an OpenMRS instance using:
curl -u <username>:<password> https://<server name>/ws/rest/v1/session
which returns this value in the response:
"sessionId":"D7C5E8BED7EDA2381E69126A40B3B22C"
I then try to use this sessionId token for a subsequent call:
curl --header 'Set-Cookie: JSESSIONID=D7C5E8BED7EDA2381E69126A40B3B22C' https://<server name>/ws/rest/v1/person?q=jim
As per the documentation this cookie should be enough to authenticate the request, but I get a “User is not logged in” message.
Any ideas why?
suthagar23
(Suthagar Kailayapathy)
2
I think you misplaced the name here
cookie named jsessionid=token.
You have named as JSESSION
. Can you please check it again?
It should be,
curl --header 'Set-Cookie: jsessionid=D7C5E8BED7EDA2381E69126A40B3B22C' https://<server name>/ws/rest/v1/person?q=jim
dsurrao
(Dominic Surrao)
3
Thanks @suthagar23, I meant to write JSESSIONID in my original post.
I tried jsessionid=token but that still doesn’t work.
dkayiwa
(Daniel Kayiwa)
4
@dsurrao can you try something like this?
curl --cookie ‘JSESSIONID= D7C5E8BED7EDA2381E69126A40B3B22C’ https://localhost:8080/openmrs/ws/rest/v1/person?q=jim
cioan
(Cosmin Ioan)
5
Thanks @dkayiwa, but that does not work either.
dkayiwa
(Daniel Kayiwa)
6
@cioan which exact commands did you run again? And what was the response?
cioan
(Cosmin Ioan)
7
Hi @dkayiwa, thank you for your help. Here are the commands I ran:
curl -i -u admin:Admin123 https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/session
curl --cookie ‘JSESSIONID=253C4851E6FB4008765D242D8FE0E562’ https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/patient?q=Mark
And there is no response at all.
dkayiwa
(Daniel Kayiwa)
8
Use a single apostrophe for wrapping the session id as here: https://pastebin.com/iQxmiJc0
1 Like
cioan
(Cosmin Ioan)
9
Thanks @dkayiwa! That worked! I will paste here the working command syntax:
curl -i -u admin:Admin123 https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/session
curl --cookie 'JSESSIONID=CC67D34FA3625E069E7B4E04451AB560' https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/patient?q=Mark
1 Like
dsurrao
(Dominic Surrao)
10
Thanks so much @dkayiwa and @cioan ! This syntax works for me as well.