Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes


Accepted answer

Permanent link
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

1 vote

Comments

Turns out curl is not necessary. I sent the following http commands without needing curl:

https://SERVER:PORT/jts/authenticated/identity
https://SERVER:PORT/jts/authenticated/j_security_check?j_username=USERID&j_password=PASSWORD

The second command returned the roles of the user, thus enabling confirmation of successful login.

Couldn't have done it without your help, though. Thanks.

correct, you don't NEED curl. bit using it demonstrates the need and solution for the session cookie returned from the 1st call.
unless you managed this is your code, the second should have failed.
if you are running with the default, Form registration.

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

Permanent link
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

0 votes

Comments

my script above works the same in 6.0.1

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938
× 479

Question asked: Jul 29 '13, 8:42 p.m.

Question was seen: 11,627 times

Last updated: Jun 09 '16, 7:58 a.m.

Confirmation Cancel Confirm