TM1 REST API Logout

Post Reply
User avatar
nlashin
Posts: 28
Joined: Tue Jun 18, 2013 10:24 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 365

TM1 REST API Logout

Post 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?
User avatar
nlashin
Posts: 28
Joined: Tue Jun 18, 2013 10:24 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 365

Re: TM1 REST API Logout

Post 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
Vish.n
Posts: 3
Joined: Thu Apr 23, 2020 8:06 am
OLAP Product: Tm1
Version: PA 2.0
Excel Version: 2016

Re: TM1 REST API Logout

Post 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!
Drg
Regular Participant
Posts: 159
Joined: Fri Aug 12, 2016 10:02 am
OLAP Product: tm1
Version: 10.2.0 - 10.3.0
Excel Version: 2010

Re: TM1 REST API Logout

Post 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
Vish.n
Posts: 3
Joined: Thu Apr 23, 2020 8:06 am
OLAP Product: Tm1
Version: PA 2.0
Excel Version: 2016

Re: TM1 REST API Logout

Post 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!!!!
Vish.n
Posts: 3
Joined: Thu Apr 23, 2020 8:06 am
OLAP Product: Tm1
Version: PA 2.0
Excel Version: 2016

Re: TM1 REST API Logout

Post 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?
Post Reply