def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
"""
Gets the id of the desired workbook to relocate.
'server' specified server address
'auth_token' authentication token that grants user access to API calls
'user_id' ID of user with access to workbook
'site_id' ID of the site that the user is signed into
'workbook_name' name of workbook to get ID of
Returns the workbook id and the project id that contains the workbook.
"""
url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
_check_status(server_response, 200)
xml_response = ET.fromstring(_encode_for_display(server_response.text))
workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
for workbook in workbooks:
if workbook.get('name') == workbook_name:
return workbook.get('id')
error = "Workbook named '{0}' not found.".format(workbook_name)
raise LookupError(error)
评论列表
文章目录