3 Replies Latest reply on Oct 30, 2017 2:45 AM by Maciek La

    Tableau REST API: Using Javascript to get the Token

    Archana Mohan

      Hello all,


      I am a complete beginner with REST API and I could not figure out how I am to proceed.

      I installed Postman and was successfully able to get the Token, but I am not sure how to send the raw XML payload in javascript.



                <credentials name ="XXX" password="YYY"  >

                     <site contenturl = "" />




      I have :

           httpRequest.open('POST', 'http://MY-SERVER/api/2.4/auth/signin', false);

           httpRequest.setRequestHeader("Content-type", "application/xml");


      Not sure how to add the xml payload. I have access to a Tableau Server(MY-SERVER) and everything.

      Any help would be greatly appreciated!


      Thank you,


        • 1. Re: Tableau REST API: Using Javascript to get the Token



          I moved this post to the Tableau Community specifically for the Rest API: REST API . There is a better chance someone in this space will be able to assist.


          I hope someone will be able to assist!




          • 2. Re: Tableau REST API: Using Javascript to get the Token
            Mossdiq Hasan



            I just gone through your question and its a very interesting question.

            previously i done something with php and javascript to send the request in xml format.

            // Inside this field you can enter your xml request code .

            // For login you don't want any header so remove the header file .

            $xml = '<?xml version="1.0" encoding="UTF-8"?>' . 

                        '<tsRequest>' .

                            '<user id="'.$Userid.'" />'.


                // print_r($post_data);

                $content_type = 'text/xml';

                $aContext = array(

                    'http' => array(

                        'method'  => 'POST',

                        'header'  => 'X-Tableau-Auth : '.$AuthToken,

                                        'Content-type: ' . addslashes($content_type) .'\r\n'

                                        . 'Content-Length: ' . strlen($xml) . '\r\n',

                        'content' => $xml,




            If you want to get auth-token with the help of php,javascript & json then the below mention code will also work for you : -





                $server = "Server Address";

                $user = "Username";

                $password = "Password";

                $siteId = "TableauWeb";

                $SignInUrl = "http://".$server."/api/2.5/auth/signin";

                $data = '{"credentials":{"name":"'.$user.'","password":"'.$password.'","site":{"contentUrl":"'.$siteId.'"}}}';

                // echo $data.'<br>';

                $options = array(

                  'http' => array(

                    'method'  => 'POST',

                    'content' => $data,

                    'header'=>  "accept: application/json,\r\n".

                                "content-type: application/json\r\n"



                $context  = stream_context_create($options);

                $result = file_get_contents($SignInUrl,false,$context);



                $response = json_decode($result);

                $responsearray = array();

                foreach($response as $responses) {

                    $item = json_decode($result,true);

                    $responsearray = array_merge($item['credentials'],$responsearray);


                $token = $responsearray['token'];

                $siteIdToken = $responsearray['site']['id'];

                $userIdToken = $responsearray['user']['id'];

                echo '<b>Token :</b> '.$token.'<br>';

                echo '<b>siteIdToken :</b> '.$siteIdToken.'<br>';

                echo '<b>userIdToken :</b> '.$userIdToken.'<br>';




                // echo $_SESSION['GTL_TableauToken'];




                    echo 'Error';









            Mohammad Mossdiq Hasan

            • 3. Re: Tableau REST API: Using Javascript to get the Token
              Maciek La

              If you would like to interact with the REST API you would have to use server side scripting language as PHP or Python. This is due to X-AUTH token being stored in the HTTP cookie which is not accessible by the Browser-side languages such as Javascript.

              However, there is an undocumented API which can be access purely with JS and it provides vast range of REST API functionality. For step by step instructions you can find my post here: