1 Reply Latest reply on Dec 11, 2019 6:01 PM by Santiago Sanchez

    Accessing total_views for viewItem (TSC)

    Farwa Iftikhar

      Hi,

       

      I am trying to access all the workbooks and then for each workbook access all the viewItems and for each viewItem get the total_views but this gives me an error:  "tableauserverclient.models.exceptions.UnpopulatedPropertyError: Usage statistics must be requested when querying for view." I am not sure what I am doing wrong in my approach.

       

      Here is my code:

       

      ```

      with server.auth.sign_in(tableau_auth):

        all_workbooks, pagination_item = server.workbooks.get()

        all_views, pagination_item = server.views.get(req_options=None, usage=True)


         for workbook in all_workbooks:

                  server.workbooks.populate_views(workbook)

                   print(workbook.name)

                   for view in workbook.views:

                        print(view.name)

                        print(view.total_views)

      ```

        • 1. Re: Accessing total_views for viewItem (TSC)
          Santiago Sanchez

          Hi Farwa,

           

          I believe what's happening is that the view object you are requesting statistics for wasn't created with the (optional) parameter 'usage=True'. I can see you use the parameter on the 3rd line to populate the pagination_item list:

           

          all_views, pagination_item = server.views.get(req_options=None, usage=True)

           

          But that's not the list you are using on the 2nd for loop (you are using workbook.views instead):

           

          server.workbooks.populate_views(workbook)

                       print(workbook.name)

                       for view in workbook.views:

           

          What happens if you iterate over the 'pagination_item' list and try to get total_views for each ViewItem object? My guess is that'd work. If that's the case I think you might need to use it instead. The ViewItem object has a workbook_id attribute that you can then use to then get the workbook name.

           

          It might be worth logging this as a feature request on GitHub - tableau/server-client-python: A Python library for the Tableau Server REST API. If there's another way to go around it, the team there might also be able to point that out.

           

          Hope this helps!

          Santiago