4 Replies Latest reply on Jun 7, 2018 8:49 PM by jegan.sivaraj

    Server users and luid

    jegan.sivaraj

      Hello,

       

      I'd like to use Rest API to get a list of all users and their luids. I tried looking at the sample codes provided for the tableauserverclient but could not understand. How do I make the code work for user lists?

       

      Here is the sample for data sources -

      import tableauserverclient as TSC

       

      tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')

      server = TSC.Server('http://SERVER_URL')

       

      with server.auth.sign_in(tableau_auth):

          all_datasources, pagination_item = server.datasources.get()

          print("\nThere are {} datasources on site: ".format(pagination_item.total_available))

          print([datasource.name for datasource in all_datasources])

        • 1. Re: Server users and luid
          Glen Robinson

          Hi Jegan

          Here is some powershell code that does this. (Save as *.ps1, and run on a Windows PC)

          Hope this helps

          Glen

           

          $server = "localhost"

          $username = "glen"

          $password = "password"

          $protocol = "http"

          $siteID = ""

           

           

          $api_ver = "2.8"

          # generate body for sign in

          $signin_body = (’<tsRequest>

            <credentials name=“’ + $username + ’” password=“’+ $password + ’” >

             <site contentUrl="’ + $siteID +’"/>

            </credentials>

          </tsRequest>’)

           

             $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/auth/signin -Body $signin_body -Method Post

             # get the auth token, site id and my user id

             $authToken = $response.tsResponse.credentials.token

             $site_ID = $response.tsResponse.credentials.site.id

             $myUserID = $response.tsResponse.credentials.user.id

           

             # set up header fields with auth token

             $headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”

             # add X-Tableau-Auth header with our auth tokents-

             $headers.Add(“X-Tableau-Auth”, $authToken)

           

             $PageSize = 100

             $PageNumber = 1

             $done = 'FALSE'

           

             While ($done -eq 'FALSE')

              {

           

               $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/sites/$site_ID/users?pageSize=$PageSize`&pageNumber=$PageNumber -Headers $headers -Method Get

               $totalAvailable = $response.tsResponse.pagination.totalAvailable

           

               If ($PageSize*$PageNumber -gt $totalAvailable) { $done = 'TRUE'}

               $PageNumber += 1

               $response.tsResponse.Users.User

              }

           

                $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/auth/signout -Headers $headers -Method Post

          1 of 1 people found this helpful
          • 2. Re: Server users and luid
            jegan.sivaraj

            Hi Glen Robinson,

             

            This was very helpful. I was able to retrieve the luids but it is missing a few users from the site. Any idea why that would be? I can see those users on the repository along with their luids. It is very strange.

             

            Thank you,

            Jegan

            • 3. Re: Server users and luid
              Glen Robinson

              Hi Jegan

              Could you give me some details? How many accounts are not appearing (out of a total number of accounts)?

              Also, are the accounts that arent being displayed Server Admins?

              Thanks

              Glen

              • 4. Re: Server users and luid
                jegan.sivaraj

                Disregard. No error in results.