TM1 REST API Logout

Post Reply
User avatar
nlashin
Posts: 28
Joined: Tue Jun 18, 2013 10:24 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2007
Location: Russia, Moscow

TM1 REST API Logout

Post by nlashin » Tue Mar 13, 2018 4:31 pm

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: 10.2.2
Excel Version: 2007
Location: Russia, Moscow

Re: TM1 REST API Logout

Post by nlashin » 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

Post Reply