Page 1 of 1

TM1 REST API Logout

Posted: Tue Mar 13, 2018 4:31 pm
by nlashin
Hello everyone!

I use JavaExtension in TI to read REST API data.
But all my connections through REST API generate separate session and finally (in TM1TOP) we have too many threads.
For closing REST API session we must use /api/logout and set TM1SessionId cookie for understanding of active session.

May be you have some examples of setting TM1SessionId cookie in Java, becouse i can't provide correct logout and session doesn't close.

My general connection code:

Code: Select all

String url = "http://xxx:8000/api/v1/Threads";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
String userCredentials = "JavaUser:apple";
String basicAuth = "Basic " + java.util.Base64.getEncoder().encodeToString(userCredentials.getBytes());
con.setRequestProperty ("Authorization", basicAuth);
String sCookie = con.getHeaderField("Set-Cookie");
In this case sCookie = "TM1SessionId=vfGcaKVQ-_OsuHS-rMs0vw; Path=/api/; HttpOnly"

Then I try to make a logout and set TM1SessionId=vfGcaKVQ-_OsuHS-rMs0vw as cookie in new request:

Code: Select all

String url_Logout = "http://xxx:8000/api/logout";
URL obj_Logout = new URL(url_Logout);
con = (HttpURLConnection) obj_Logout.openConnection();
con.setRequestProperty("Cookie", sCookie);
String sCookie2 = con.getHeaderField("Set-Cookie");
But sCookie2="TM1SessionId=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; Path=/api/; HttpOnly"

What i'm doing wrong?

Re: TM1 REST API Logout

Posted: Wed Mar 14, 2018 6:46 pm
by nlashin
Little work around (and help from Hubert Heijkers) showed that it is normal situation when TM1SessionId=/ after setting session cookie. The Set-Cookie header which i receive in the response to the logout request actually confirms that the session has been closed, it instructs the client to clear/expire the previously set TM1SessionId cookie.

And I already fix the situation with many threads by using command: ActiveSession/tm1.Close

Re: TM1 REST API Logout

Posted: Mon Apr 27, 2020 9:41 am
by Vish.n
Hi, i am facing similar problem and get the same response as you have mentioned in the problem statement...I did try ActiveSession/tm1.Close and passed the session id (similar way you have done above)..I do receieve 204 response but still the session stays...anything further i am missing here? Earlier it worked not sure due to some reason i am facing this....can you please help!

Re: TM1 REST API Logout

Posted: Mon May 04, 2020 2:03 pm
by Drg
Hi.

you have a 2 variante to close session correctly.

1 if you need close current session use logout https://www.ibm.com/support/knowledgece ... _auth.html

2 if you need close any user session
/api/v1/Threads('thread№')/tm1.CancelOperation
or if you need kill alt user threads and log out him
/api/v1/Users('UserId or alias')/tm1.Disconnect

Re: TM1 REST API Logout

Posted: Fri May 08, 2020 2:19 pm
by Vish.n
I am running thr threads in parallel with the same account..so need to close them with session ID..cant use cancel or disconnect and logout is for lower versions of PA..ActiveSession/tm1.Close should be ideally working but might be headers or body i am missing something!!!!

Re: TM1 REST API Logout

Posted: Sat May 09, 2020 12:11 pm
by Vish.n
nlashin wrote: Wed Mar 14, 2018 6:46 pm Little work around (and help from Hubert Heijkers) showed that it is normal situation when TM1SessionId=/ after setting session cookie. The Set-Cookie header which i receive in the response to the logout request actually confirms that the session has been closed, it instructs the client to clear/expire the previously set TM1SessionId cookie.

And I already fix the situation with many threads by using command: ActiveSession/tm1.Close
Was there anything apart this command needs to be reviewed?