REST API call with JSESSIONID=token not working

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:


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?

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

Thanks @suthagar23, I meant to write JSESSIONID in my original post.

I tried jsessionid=token but that still doesn’t work.

@dsurrao can you try something like this?

curl --cookie ‘JSESSIONID= D7C5E8BED7EDA2381E69126A40B3B22C’ https://localhost:8080/openmrs/ws/rest/v1/person?q=jim

Thanks @dkayiwa, but that does not work either.

@cioan which exact commands did you run again? And what was the response?

Hi @dkayiwa, thank you for your help. Here are the commands I ran:

curl -i -u admin:Admin123
curl --cookie ‘JSESSIONID=253C4851E6FB4008765D242D8FE0E562’

And there is no response at all.

Use a single apostrophe for wrapping the session id as here:

1 Like

Thanks @dkayiwa! That worked! I will paste here the working command syntax:

curl -i -u admin:Admin123
curl --cookie 'JSESSIONID=CC67D34FA3625E069E7B4E04451AB560'
1 Like

Thanks so much @dkayiwa and @cioan ! This syntax works for me as well.