How to login via the REST API?
![]()
I can pass HTTP commands via the REST API without issue if I am already logged in via another browser window. However if I am not, I get the prompt for username and password. How do I pass the username and password as part of the HTTP command via the REST API? For example, what would you add to the following to also login?
https://SERVER:PORT/jts/rpt/repository/foundation?fields=foundation/contributor/(userId|name|archived)&size=999 I tried &usedId=xxxxx&password=xxxx but that was ignored - didn't even get an error. |
Accepted answer
![]()
logon is a two step process, it cannot be embedded in another call.
here is a little batch file using curl that will logon and get the list of projects on a server set the user, password and host variables set COOKIES=.\cookies.txt set USER= set PASSWORD= set HOST=https://localhost:9743 curl -k -c %cookies% "%host%/jts/authenticated/identity" curl -k -L -b %COOKIES% -c %COOKIES% -d j_username=%USER% -d j_password=%PASSWORD% "%host%/jts/authenticated/j_security_check" curl -k -L -b %COOKIES% "%host%/ccm/oslc/workitems/catalog Ralph Schoon selected this answer as the correct answer
Comments Turns out curl is not necessary. I sent the following http commands without needing curl:
correct, you don't NEED curl. bit using it demonstrates the need and solution for the session cookie returned from the 1st call.
I am hoping that cookie management is automatic and not something I'll have to worry about, at least that has been the case in the past. I'll find out when I try to create code with these calls this weekend.
I've never seen ANY code do automatic cookie mgmt..
|
One other answer
![]()
Hi Mike,
This was working on 5.0.2 and in 6.0.1 its not working. Would you please provide how to login to 6.0.1 via restapi. Regards, Dibyandu Roy |