12 Replies Latest reply on Feb 23, 2018 3:17 PM by Tim Kerans

    REST API Get Image with field parameter

    Antoine Tignon

      Hi,

      Is it possible using the REST API to get an image from a view using a parameter from the view itself like it is done with a HTTP GET like this : "http://localhost/views/workbook/view.png?fieldA=165"

      I made the "Query view image" work with python, but i don't know if it's possible to user a field like "fieldA" above in it and if i has to be done when i get the view_id or after when i get the image.

      Thanks for your help

        • 1. Re: REST API Get Image with field parameter

          Bonjour Antoine Tignon

           

          In Tableau 10.2/API version 2.5, there's a new method there for getting high resolution:

          Query View Image

           

          Let me know if you need further assistance.

           

          ----------

          Lénaïc RIÉDINGER, Global Community Engineer Tableau

          Tableau Community Forums | Knowledge Base

          If you see a Helpful or Correct response, please mark it thanks to the buttons below the targeted post!

          1 of 2 people found this helpful
          • 2. Re: REST API Get Image with field parameter
            Glen Robinson

            Hi Antoine

            I have tried this a number of ways, and have never got it to work.

            My solution was to mix REST API authentication with a GET URL request.

            This seems to work, (and allow the addition of Parameters)

            Have attached some code below (Powershell) which works for me

            Hope this helps

            Glen

             

             

            $server = "http://localhost:"

            $username = "glen"

            $password = "password"

            $protocol = 'http'

            $siteID =""

             

            # Login to Server

            # generate body for sign in

            $signin_body = (’<tsRequest>

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

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

              </credentials>

            </tsRequest>’)

             

            $Uri = "$server/api/2.6/auth/signin"

            $response = Invoke-RestMethod -Uri $uri -Body $signin_body -Method Post

             

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

               $authToken = $response.tsResponse.credentials.token

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

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

               $authToken

             

            $URL = "http://localhost/views/Superstore/Product.png:?refresh=yes&Region=South"

            $destination = "C:\temp\Products_South.png"

             

            $webClient = New-Object System.Net.WebClient

            $webClient.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "workgroup_session_id="+$authToken)

            $webClient.DownloadFile($URL, $destination)

             

            # Sign Out of Server

            $response = Invoke-RestMethod -Uri $server/api/2.6/auth/signout -Headers $headers -Method Post

            2 of 2 people found this helpful
            • 3. Re: REST API Get Image with field parameter
              Antoine Tignon

              Thanks Glen, I did the same thing but in a python code

              It seems that the REST API only is not currently usable for that kind of thing.

              • 4. Re: REST API Get Image with field parameter
                Glen Robinson

                Agree.

                Cant download PDF / CSV either. am sure it will come though

                All the best

                Glen

                • 5. Re: REST API Get Image with field parameter
                  ozan kececioglu

                  Thanks Glen, saved my day. I wasted a good time to find a way to do that through REST api and it is not possible yet as it turns out. I will do it as you did.

                  • 6. Re: REST API Get Image with field parameter
                    Russell Hay

                    Hey,

                     

                    In Tableau 10.5, you will be able to get images with filtering enabled.  If you download the 10.5 beta for server, you can try it out right now.  We've added the ability to apply filtering to the view before exporting by adding URL parameters.

                     

                    There is one caveat in the way you construct the URL.  In your example, your parameter name is fieldA.  In order to specify this in the REST api, you'll need to prepend a vf_ to the field name, so it would be vf_fieldA.

                     

                    This is a beta, so let us know if you run into any issues.

                    • 7. Re: REST API Get Image with field parameter
                      Tim Kerans

                      I just figured out the way to use the Powershell Invoke-RestMethod with the REST API for Query View Image and get a png out while adding onto Glen's snippet, although this doesn't work with a parameter other than the "high_resolution=yes" URL Parameter, but thought I would share the example:

                       

                      Here's the example:

                      $server = "http://servername"

                      $username = "username"

                      $password = "password"

                      $protocol = 'http'

                      $siteID =""

                       

                      # generate body for sign in

                      $signin_body = (’<tsRequest>

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

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

                      </credentials>

                      </tsRequest>’)

                       

                      #Sign into Server

                      $Uri = "$server/api/2.7/auth/signin"

                      $response = Invoke-RestMethod -Uri $uri -Body $signin_body -Method Post

                       

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

                      $authToken = $response.tsResponse.credentials.token

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

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

                      $siteid = $response.tsresponse.credentials.site.id

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

                       

                      #This gets all of the views

                      $uriforviews = "$server/api/2.7/sites/$siteid/views"

                      $views = Invoke-RestMethod -Uri $uriforviews -Method Get -Headers $headers

                       

                      #Will need to determine which view you need here based on the views gathered above

                      #(foreach and/or "-match" comparison operator), just grabbing the first in this example:

                      $viewidtoget = $views.tsResponse.views.view.id[0]

                       

                      #Set URL for that view

                      $URL = "$server/api/2.7/sites/$siteid/views/$viewidtoget/image?resolution=high"

                      $destination = "C:\temp\FILENAME.png"

                       

                      #Retrieve file using Invoke-RestMethod and write content to out-file destination

                      Invoke-RestMethod -Uri $url -Headers $headers -Method Get -ContentType "image/png" -OutFile $destination

                       

                      # Sign Out of Server

                      $response = Invoke-RestMethod -Uri $server/api/2.7/auth/signout -Headers $headers -Method Post

                      • 8. Re: REST API Get Image with field parameter
                        Timothy Ip

                        Hi Antoine,

                         

                        I've been trying to do this exact same thing for the last couple of hours in Python. Would you be able to share your code?

                         

                        Thanks

                         

                        Tim

                        • 9. Re: REST API Get Image with field parameter
                          Adi Cohen

                          Hi Antoine Tignon,

                          Can you please share with us the python code that you used in order to get the image using url ?

                          Thanks,

                          Adi

                          • 10. Re: REST API Get Image with field parameter
                            Adi Cohen

                            Hi Timothy Ip

                            Did you manage to sort this issue ?

                            • 11. Re: REST API Get Image with field parameter
                              Eric Harlan

                              Hey Russell,

                               

                              Thanks for this info! I was able to test it and confirm it's working on 10.5 (now that it's out of beta). Do you know if/when the REST API documentation will be updated? If I hadn't stumbled across this thread, I wouldn't have know about the new feature.

                              • 12. Re: REST API Get Image with field parameter
                                Tim Kerans

                                Hello Eric,

                                 

                                I have created a request to have the REST API documentation updated to include this feature as well as to provide a few basic examples.

                                Thanks for pointing out that although it works in Tableau Server 10.5, it does not appear in the documentation for the REST API, and for keeping us on our toes!

                                 

                                We appreciate the feedback!