#add a user to scubscription on a workbook on a Schedule is not working
#Subscription script- runs but does not create a subscription for a user on workbook, of a schedule
import tableauserverclient as tsc
tauth = tsc.TableauAuth('ID', 'PWD', site_id='Sitename') server = tsc.Server('serverURL', use_server_version=True) server.auth.sign_in(tauth)
#to get workbookID req_option = tsc.RequestOptions() req_option.filter.add(tsc.Filter(tsc.RequestOptions.Field.Name, tsc.RequestOptions.Operator.Equals, 'Product Version Dashboard test 2')) workobj = server.workbooks.get(req_option) print('workobj', workobj[0][0].name) workbookid = workobj[0][0].id print(workbookid)
target = (workbookid, 'workbook')
print('target:', target)
#To get schedule ID of schedule "11AM EST Daily" subobj= server.schedules.get() for sbj in subobj[0]: if sbj.name =="11AM EST Daily": sbjid = (sbj.id) print(sbj.name ,sbjid)
print('sbj', sbj[0][0])
req_opt = tsc.RequestOptions() req_opt.filter.add(tsc.Filter(tsc.RequestOptions.Field.Name, tsc.RequestOptions.Operator.Equals, 'cordellr')) u = server.users.get(req_opt) print('u', u) uid = u[0][0].id print('uid',uid)
subscipid = server.subscriptions.get() print('subscipid', subscipid[0][0].target)
create a new SubscriptionItem object.
newSub = tsc.SubscriptionItem('My Subscription', sbjid, uid, target) print('newSub', newSub)
#output generated: but the subscription did not get created for user who is Site admin having all access #to the site connection #newSub <Subscription subject(My Subscription) schedule_id(eb92f0ab-0cfc-422d-#b87e-1e23522f1106) #user_id(62d9dee9-10c8-4fcf-ab04-99981f770204) target(('c95c0459-#34ea-47e1-8871-#badcab1e875c', 'workbook'))
I am trying to run script to get a subscription created for a user on a workbook. Script generated new SubscriptionItem object. But upon checking on server, subscription was not created. Please help if there is any issue in API code put above.
create a new SubscriptionItem object.
newSub = TSC.SubscriptionItem('My Subscription', schedule, user, target)
Seconding this problem, the issue appears to be in the way that the library parses the 'target' argument from SubscriptionItem object. The documentation suggests that we should be passing a tuple "(view_id, view_type)" but this is raising an error when converting over to XML.
<
AttributeError: 'tuple' object has no attribute 'id'
When creating a new subscription, you should use the provided TSC.Target object, instead of defining your own tuple. That should prevent the above errors.
So instead of this,
target = (workbookid, 'workbook')
you should use Target class:
target = TSC.Target(workbookid, 'workbook')
Note that there has been a bug with using the Target object, but that has been fixed with #377. The fix is merged into the 'development' branch.
Thanks Shinchris, finding this very useful to encourage adoption from our users
Closing old issues. @shinchris provided the answer. Please open a new issue if there are still questions or things still aren't working.