You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
#add a user to scubscription on a workbook on a Schedule is not working #366
#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)
#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.
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.
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.
Activity
mehuldan commentedon Nov 21, 2018
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)
Jaunson commentedon Jan 17, 2019
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.
<>\tableauserverclient\server\request_factory.py in create_req(self, subscription_item)
431
432 content_element = ET.SubElement(subscription_element, 'content')
--> 433 content_element.attrib['id'] = subscription_item.target.id
434 content_element.attrib['type'] = subscription_item.target.type
435
AttributeError: 'tuple' object has no attribute 'id'
shinchris commentedon Jan 18, 2019
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.
Jaunson commentedon Jan 18, 2019
Thanks Shinchris, finding this very useful to encourage adoption from our users
irwando commentedon Jul 25, 2019
Closing old issues. @shinchris provided the answer. Please open a new issue if there are still questions or things still aren't working.