4 Replies Latest reply on Oct 18, 2019 7:05 AM by Bret Beatty

    How to see a data source id by feeding the datasource name

    Bret Beatty

      Hello,

       

      I am working in Tableau Server Client and I'd love to program a datasource refresh in Python. I've been banging my head against my desk trying to get it to work. How am I supposed to determine the datasource_id?

        • 1. Re: How to see a data source id by feeding the datasource name
          Subodh Gupta

          Hi,

           

          If you are looking to refresh a single data source by passing its name, you need something like:

           

            request_option = TSC.RequestOptions()

              request_option.filter.add(TSC.RequestOptions.Field.Name,TSC.RequestOptions.Operator.Equals,<name>)

           

          followed by something like:

          server.datasources.get(req_option)

          • 2. Re: How to see a data source id by feeding the datasource name
            Bret Beatty

            I’m not getting an error, but I’m still a bit lost. I’m fairly new to Python. I did what you recommended,

             

            with server.auth.sign_in(tableau_auth):

                request_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,TSC.RequestOptions.Operator.Equals,'ACDC_avature'))

                server.datasources.get(request_option)

             

            But now I’m a bit lost as to what to do next. It is returning the below, which I have no idea what it means.

             

            ([<tableauserverclient.models.datasource_item.DatasourceItem object at 0x0000023122C580F0>],

            <tableauserverclient.models.pagination_item.PaginationItem object at 0x0000023122C58080>)

             

            I wanted to be able to pass the datasource name and then have it return the datasource ID so when I run the refresh I can do get_by_id().

            • 3. Re: How to see a data source id by feeding the datasource name
              Subodh Gupta

              Hi,

               

              Barely a novice myself

              Will try to share what I know so far.  Since theoretically, it's possible that there can exist multiple data sources with the same name, what you are getting back is a pageination_item/list of all data sources with that name. In your case, that list may possibly only contain one item.

               

               

               

                  request_option = TSC.RequestOptions()

                  request_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, args.name))

               

              ## The above is what I shared with you earlier

               

              ## In the following code, if you replace workbooks/workbook with datasources/datasource, it may work for you.

               

                      all_workbooks, pagination_item = server.workbooks.get(request_option)

                      print("\nThere are {} workbooks for project {} on site: {}".format(pagination_item.total_available, args.project_name, args.site))  ##Remove args.project_name, args.site if they are not variables in your script.

                      for workbook in all_workbooks:

                          try:

                              print("Refreshing:" + workbook.name)

                              results = server.workbooks.refresh(workbook.id)

                          except:

                              print("Refresh already scheduled for:" + workbook.name)

               

              EDIT: Note that this does not wait for the refresh to complete or capture the jobid to display/output to console. It just triggers the job. Also, there is barely any exception handling.

              • 4. Re: How to see a data source id by feeding the datasource name
                Bret Beatty

                Thanks again for the help.

                 

                I can’t get this to work the way I need.

                 

                Regards,

                 

                Bret Beatty | Performance and Analytics Senior Analyst

                6000 American Parkway | Madison, WI 53783

                Office: 608.242.4100 ext. (35178)

                <https://www.facebook.com/amfam>  <https://twitter.com/amfam>   <https://www.linkedin.com/company/american-family-insurance>

                <http://www.amfam.com/>

                P Please consider the environment before printing this e-mail.