Tag Archives: task api

PHP Function for get a session using TASK API with IIS

Hello there!

I’ve created a PHP function to help you create a session using TASK API for PHP with IIS.

Here is the code:


function authenticationMSTR($server, $project, $user, $pass, $documentId, $dashboardMode) {
$projectUrl = str_replace(" ","%20",$project);
$projectTask = str_replace(" ","+",$project);
$username = 'username';
$password = 'password';

$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")

$url = file_get_contents("http://$server/MicroStrategy/asp/TaskAdmin.aspx?


foreach($data->children() as $child) {
foreach($child->children() as $child1) {
$sessionmstr = $child1;

echo "http://$server/MicroStrategy/asp/Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0&currentViewMedia=$dashboardMode&documentID=$documentId&server=$server&Project=$projectUrl&port=0&share=1&hiddensections=header,path,dockTop,dockLeft,footer&usrSmgr=$sessionmstr";


$server: is your server ip/dns
$project: Name of the project
$user: MicroStrategy Username
$pass: MicroStrategy Username Password 
$documentId: Document ID
$dashboardMode: View media. Example: Use 8 for flash and 2 for DHTML.
$username = Put the Username for login in your TaskAdmin page. 
$password = Put the password for the Username used to login in TaskAdmin page.

Just save this in a file as Authentication.php. Now create another file like this:

include "Authentication.php";
<?php header("Content-Type: text/html; charset=ISO-8859-1",true);?>


Just use your own info in those above parameters.

Save this file as test.php in the same folder that you saved your Authentication.php.
Those files must be saved inside your Apache PHP folder. If you use Xampp, is must be saved inside the htdocs folder.

Open test.php in your browser and you will see your dashboard!


Hope it helps!

God bless you!

Using TASK API getSessionState with .net

Hello there!

One of the coolest things that MicroStrategy can do is the ability to embed reports/dashboards using URL API in  a portal, for example. You just have to copy the link of a report/document and paste it in an HTML code to display them. By default, the user needs to fill the login form to see the report/dashboard. If you don’t want that, you can insert 2 parameters in the URL: uid and pwd, so the user is automatically signed it.

Here is an example of URL API to display a specific dashboard:

http://localhost/MicroStrategy/asp/Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0&currentViewMedia=2&documentID=68D3815340CDA9BF858B9EB715EC3A88&server=server1&Project=MicroStrategy%20Tutorial&port=0&share=1&hiddensections=header,path,dockTop,dockLeft,footer&uid=administrator&pwd=123456" width="1024" height="768" />

Everybody knows that using this approach wouldn’t be a good idea, because you show to everyone that sees the code an user to login to your projects. You can hide that login using TASK API. TASK API is an MicroStrategy API that uses Tasks (you can even create your own Tasks) to do some processes. To access TASK API page use one of these URLs:

For ASP.NET: http://localhost/MicroStrategy/asp/TaskAdmin.aspx

For J2EE: http://localhost/MicroStrategy/servlet/taskAdmin

You have to enter an OS (Operational System) user to login to this page. Once logged you have to:

1. Create a getSessionState link. To do that, just follow this TN: https://resource.microstrategy.com/support/Authoring/DisplayTN.aspx?tnkey=31236&formatted=1

2. If you are going to use .net with MicroStrategy Web ASP.NET , you can use this code below in your controller (just substitute the strings like username and password with your own data:

String url="https://localhost/MicroStrategy/asp/TaskAdmin.aspx?taskId=getSessionState&taskEnv=xml&taskContentType=xml&server=server1&project=tutorial&uid=administrator&pwd=thepassword";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "GET";
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = new NetworkCredential("username", "password", "domain");
// username and password are information about and Windows account, so you have to insert
HttpWebResponse response;
Stream stream;
StreamReader streamReader;
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
streamReader = new StreamReader(stream);
string stringXml = streamReader.ReadToEnd();
String[] str = new string[] { "<min-state>", "</min-state>" };
string[] mstrSession= stringXml.Split(str,3, StringSplitOptions.None);

string url2 = "https://localhost/MicroStrategy/asp/Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0&currentViewMedia=2&documentID=8AF8FCJHDY1234125CD&server=server1&Project=tutorial&port=0&share=1&hiddensections=header,path,dockTop,dockLeft,footer&usrSmgr=" + mstrSession[1];
return url2;

Just remember to use your report/document URL .

Just create a view to display this code.

Hope it helps.


God bless you!