← 输入框|github.com|刷新
Skip to content

#add a user to scubscription on a workbook on a Schedule is not working #366

Closed

Description

@mehuldan

#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'))

Activity

  1. mehuldan commented on Nov 21, 2018

    @mehuldan
    Author

    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)

  2. Jaunson commented on Jan 17, 2019

    @Jaunson

    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'

  3. shinchris commented on Jan 18, 2019

    @shinchris
    Contributor

    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.

  4. Jaunson commented on Jan 18, 2019

    @Jaunson

    Thanks Shinchris, finding this very useful to encourage adoption from our users

  5. irwando commented on Jul 25, 2019

    @irwando

    Closing old issues. @shinchris provided the answer. Please open a new issue if there are still questions or things still aren't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions