tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
656 stars 420 forks source link

TSC.SubscriptionItem, Payload is either malformed or incomplete. (0x5CE10192 : Specifying subscription attachments not allowed.) #1430

Open gdrau opened 1 month ago

gdrau commented 1 month ago

Hello, I'm trying to create a subscription for a user on a view. I put this piece of code, schedule_id = '60c392fc-d902-44b0-92cf-cfa3b512630f' user_id = df[0].values[i]

Create the new SubscriptionItem object with variables from above.

    new_sub = TSC.SubscriptionItem('EssaiGD', schedule_id, user_id, target)

    # (Optional) Set other fields. Any of these can be added or removed.
    new_sub.attach_image = True
    new_sub.attach_pdf = True
    new_sub.message = "You have an alert!"
    new_sub.page_orientation = TSC.PDFRequestOptions.Orientation.Portrait
    new_sub.page_size_option = TSC.PDFRequestOptions.PageType.A4
    new_sub.send_if_view_empty = True

    # Create the new subscription on the site you are logged in.
    new_sub = server.subscriptions.create(new_sub)

I launch it and when I have the error it gives me 0x5CE10192 : Specifying subscription attachments not allowed.

THanks

Version : Product version: 2024.2.0 REST API version: 3.23 Build number: 20242.24.0711.1807 Python 3.10.6

jorwoods commented 1 month ago

From the REST API documentation:

If subscriptions to attachments are disabled in Tableau server or site settings, then making a request that sets attachImage to false will cause an error.

gdrau commented 1 month ago

the parameters are true and not false in my script. So when I manually create the subscription or when I use a request it works. So I don't understand why it doesn't work

gdrau commented 1 month ago

image

jorwoods commented 1 month ago

What happens if you set image to True, pdf to False, and remove the pdf specific options? Try the simplest case first.

gdrau commented 1 month ago

image the same

gdrau commented 1 month ago

image

gdrau commented 1 month ago

image

gdrau commented 2 weeks ago

?? Help me :-)

jorwoods commented 2 weeks ago

My minimally reproducible example works. edit: Also attaching image. Still works.

# /// script
# requires-python = ">=3.10
# dependencies = [
#   "tableauserverclient>=0.32.0",
#   "python-dotenv"
# ]
# ///

import os

from dotenv import load_dotenv
import tableauserverclient as TSC

load_dotenv()

auth = TSC.PersonalAccessTokenAuth(
    token_name=os.environ["TABLEAU_TOKEN_NAME"],
    personal_access_token=os.environ["TABLEAU_PAT"],
    site_id=os.environ["TABLEAU_SITE"]
)

server = TSC.Server(os.environ["SERVER_ADDRESS"], use_server_version=True)
with server.auth.sign_in(auth):
    workbook = server.workbooks.filter(name="Team Metrics")[0]
    target = TSC.Target(workbook.id, "workbook")

    # Pick a random schedule for testing purposes
    sched = next(s for s in TSC.Pager(server.schedules) if s.schedule_type == TSC.ScheduleItem.Type.Subscription)

    sub = TSC.SubscriptionItem("message", schedule_id=sched.id, user_id=server.user_id, target=target)
    sub.attach_image = True
    sub.attach_pdf = True
    sub.page_orientation = TSC.PDFRequestOptions.Orientation.Portrait
    sub.page_size_option = TSC.PDFRequestOptions.PageType.A4
    sub.send_if_view_empty = True

    sub = server.subscriptions.create(sub)