1 Reply Latest reply on Nov 16, 2018 7:22 AM by Swaminathan Jayaraman

    How to edit connection published datasource - python rest API

    Josef Freedman

      Hi All,

       

      We are migrating server, and I would like to move over several published datasource to point at the new SQL server, rather than the old one.

       

      I am not well versed in python, so hopefully this is just something small that I have overlooked. I could do this manually, but I would like to script this, as it may also be helpful in the future for moving from dev to live environments.

       

      Here is what I have tried so far:

       

      import tableauserverclient as TSC

      server = TSC.Server('https://server', use_server_version=True)

      tableau_auth = TSC.TableauAuth('username', 'password')

      server.auth.sign_in(tableau_auth)

       

      datasource = server.datasources.get_by_id('datasource_id_string')

      #I got the datasource_id_string earlier on, I'm testing it against a specific one.

       

      server.datasources.populate_connections(datasource)

      print(datasource.connections[0].id)

       

      print(datasource.connections[0].server_address)

       

      datasource.connections[0].server_address = 'new ip'

      datasource.connections[0].username = 'user'

      datasource.connections[0].password = 'password'

      datasource.connections[0].embed_password = True

      server.datasources.update(datasource)

       

      I received back:

       

      <tableauserverclient.models.datasource_item.DatasourceItem object at id_string>

      print(datasource.connections[0].server_address)

       

      I notice the datasource connections has not changes.

      datasource.connections[0].server_address = (old ip)

       

      I have tried the following, but I don't think I have had the context correct:

       

      datasource.update_connection(datasource_item, connection_item)

       

      I then tried server.datasources.update_connection(datasource,datasource.connections[0]) but this also seems to not be updating the connection.

       

      Based on API reference

       

      Is anybody able to assist on this?

       

      Thank you in advance.

       

      J