Skip to content

fix: build the Share embed snippet for a view - #1933

Open
ranjithguggilla wants to merge 2 commits into
tableau:developmentfrom
ranjithguggilla:fix/996-view-embed-code
Open

ranjithguggilla wants to merge 2 commits into
tableau:developmentfrom
ranjithguggilla:fix/996-view-embed-code

Conversation

@ranjithguggilla

@ranjithguggilla ranjithguggilla commented Nov 22, 2026 •

Copy link
Copy Markdown

Closes #996

Motivation

There is no REST method that returns the embed HTML from a view's Share button. The snippet is built from the view URL. Jac Fitzgerald noted that adding it would be useful. The issue is labeled ui-exists because the UI has the snippet and the REST API does not.

Behavior change

views.embed_code(view) returns that HTML for the signed-in site.

  • REST API 3.14 and later (Tableau 2021.4; the version table maps 3.13 to 2021.3 and 3.14 to 2021.4, and the Embedding API v3 library is hosted from 2021.4): a tableau-viz element and tableau.embedding.3.latest.min.js.
  • Older servers, including REST API 3.13: the JavaScript API object embed that loads viz_v1.js.

A named site uses /t/{site}/views/{workbook}/{view}. The default site uses /views/{workbook}/{view}.

toolbar="bottom" and hide-tabs are fixed, and the older snippet uses tabs=no and toolbar=yes. Neither snippet sets a width or height. Callers edit the returned HTML to change those.

Test plan

Tests cover the legacy snippet, the 3.13/3.14 boundary, the v3 snippet on the default site and on a named site, NotSignedInError, both MissingRequiredFieldError paths, and a site and workbook name containing & or '.

Not covered: pasting the snippet into a browser against a Tableau site.

The REST API does not return the embed HTML from the Share button.
views.embed_code builds it from the view URL: the Embedding API v3
component on REST API 3.13 and later, and the JavaScript API object
embed on older servers.
@jacalata

Copy link
Copy Markdown
Contributor

Thanks for this, @ranjithguggilla. One version-gate problem, plus a few questions.

Needs fixing: version gate (views_endpoint.py, check_at_least_version("3.13"))

The PR body says REST 3.13 is Tableau 2021.4. The REST API versions table maps 3.13 to 2021.3 and 3.14 to 2021.4, and the Embedding API docs say the v3 library is hosted on Tableau Server from 2021.4. On a 2021.3 server this builds a snippet whose script URL doesn't exist. Could you gate at 3.14 and correct the PR body? A boundary test at 3.13 and 3.14 would cover it.

Questions

  • self.parent_srv.site_url raises NotSignedInError before sign-in, and a missing or malformed content_url raises MissingRequiredFieldError. The docstring has no Raises section. Could you add one, along with Parameters and Returns as on neighbouring methods?
  • The snippet is fixed (toolbar="bottom" hide-tabs, tabs=no, no width or height). Is that what the Share dialog's defaults give? A short docstring note that callers edit attributes themselves would help.
  • No test covers the two MissingRequiredFieldError paths, or HTML escaping of a site or workbook name containing ' or &.

Drafted with AI assistance (Claude); reviewed and posted by Jac.

The version table maps 3.13 to Tableau 2021.3 and 3.14 to 2021.4, and
the v3 embed library is hosted from 2021.4. A 3.13 server now gets the
older snippet. The docstring lists the fixed toolbar settings and the
errors, and the tests cover those errors and names that contain & or '.
@ranjithguggilla

Copy link
Copy Markdown
Author

Addressed in 575aacf.

The v3 snippet now starts at REST API 3.14. The version table maps 3.13 to Tableau 2021.3 and 3.14 to 2021.4, and the Embedding API v3 library is hosted from 2021.4. test_embed_code_uses_the_legacy_snippet_on_2021_3 and test_embed_code_uses_embedding_api_v3 are that boundary. The pull request body matches.

The docstring now has Parameters, Returns, and Raises (NotSignedInError, MissingRequiredFieldError). It also says toolbar="bottom" and hide-tabs are fixed, the older snippet uses tabs=no and toolbar=yes, neither snippet sets a width or height, and callers edit the HTML to change those.

test_embed_code_requires_a_signed_in_site_and_a_content_url covers the unsigned server and both content-URL errors. test_embed_code_escapes_names uses a site A&B and a workbook Rock&Roll / view O'Hare: the older snippet HTML-escapes them, and the v3 URL percent-encodes them.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get the Embed code of the workbook views

2 participants