Sometimes, i received error that flow id 35 does not exist, eventho i'm confidence the flow exist inside the server. Can anyone help with this? Below are the code with the error.
For your information, i want to avoid creating .bat file and using task scheduler. I want to use python now
@Hafiz Naim Bin Sahidi
Hi, use the following code to run flows on Tableau Server:
####
# This script demonstrates how to use the Tableau Server Client
# to run the flow
#
# For signing into server, this script uses personal access tokens. For
# more information on personal access tokens, refer to the documentations:
# (https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm)
#
# If you don't know the flow name, the script list the flows name. If you need the list
# of flows, just enter any name in the flow parameter
#
# To run the script, you must have installed Python 3.5 or later.
####
import argparse
import logging
import tableauserverclient as TSC
def main():
parser = argparse.ArgumentParser(description='Publish a datasource to server.')
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-i', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--flow-name', '-f', required=True,
help='The name of the flow')
args = parser.parse_args()
# Sign in to server
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
all_flow_items, pagination_item = server.flows.get()
print("There are {} flows on site:" .format(pagination_item.total_available))
print([[flow.id, flow.name] for flow in all_flow_items])
for flow in all_flow_items:
if flow.name == args.flow_name:
print('Run Flow', flow.name, 'Now')
# run the flow and get the JobItem
job = server.flows.refresh(flow)
print("Thanks for using this python script by www.modux.co")
if __name__ == '__main__':
main()
We can modify this flow to not use args:
####
# This script demonstrates how to use the Tableau Server Client
# to run the flow
#
# For signing into server, this script could use personal access tokens. For
# more information on personal access tokens, refer to the documentations:
# (https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm)
#
# If you don't know the flow name, the script list the flows name. If you need the list
# of flows, just enter any name in the flow parameter
#
# To run the script, you must have installed Python 3.5 or later.
####
import tableauserverclient as TSC
def main():
SERVER = "www.yourserver.com"
#Use "" for default site
SITE = ""
USER = "youruser"
PWD = "yourpassword"
FLOW_NAME = "Your Flow Name"
#Use the following for PAT Sign in
#TOKEN_NAME = ""
#TOKEN_VALUE = ""
# Sign in to server with PAT
#tableau_auth = TSC.PersonalAccessTokenAuth(TOKEN_NAME, TOKEN_VALUE, site_id=SITE)
# Sign in to server with USER/PWD
tableau_auth = TSC.TableauAuth(USER, PWD)
server = TSC.Server(SERVER, use_server_version=True)
with server.auth.sign_in(tableau_auth):
all_flow_items, pagination_item = server.flows.get()
#print("There are {} flows on site:" .format(pagination_item.total_available))
#print([[flow.id, flow.name] for flow in all_flow_items])
for flow in all_flow_items:
if flow.name == FLOW_NAME:
print('Run Flow', flow.name, 'Now')
# run the flow and get the JobItem
job = server.flows.refresh(flow)
print("Thanks for using this python script by www.modux.co")
if __name__ == '__main__':
main()
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador