diff --git a/tableauserverclient/server/endpoint/views_endpoint.py b/tableauserverclient/server/endpoint/views_endpoint.py
index c2779b17d..32d70a46b 100644
--- a/tableauserverclient/server/endpoint/views_endpoint.py
+++ b/tableauserverclient/server/endpoint/views_endpoint.py
@@ -1,5 +1,7 @@
+import html
import logging
from contextlib import closing
+from urllib.parse import quote
from tableauserverclient.models.permissions_item import PermissionsRule
from tableauserverclient.server.endpoint.endpoint import QuerysetEndpoint, api
@@ -461,6 +463,81 @@ def update_tags(self, item: ViewItem) -> None:
"""
return super().update_tags(item)
+ def embed_code(self, view: ViewItem) -> str:
+ """
+ Build the Share-dialog embed snippet for a view.
+
+ The REST API does not return this HTML. It is built from the view
+ URL. Tableau Server hosts the Embedding API v3 library from 2021.4,
+ which the REST version table maps to API 3.14 (3.13 is Tableau
+ 2021.3). Older servers get the JavaScript API object embed.
+
+ ``toolbar="bottom"`` and ``hide-tabs`` are fixed, and the older
+ snippet uses ``tabs=no`` and ``toolbar=yes``. Neither snippet sets a
+ width or height. Edit the returned HTML to change those.
+
+ Parameters
+ ----------
+ view : ViewItem
+ A view whose content URL names the workbook and the view. The
+ site comes from the signed-in server.
+
+ Returns
+ -------
+ str
+ The embed snippet.
+
+ Raises
+ ------
+ NotSignedInError
+ The server has no site URL yet.
+ MissingRequiredFieldError
+ The view has no content URL, or the content URL does not name
+ both a workbook and a view.
+ """
+ if not view.content_url:
+ raise MissingRequiredFieldError("View item missing content URL.")
+ parts = [part for part in view.content_url.split("/") if part]
+ if len(parts) < 2:
+ raise MissingRequiredFieldError("View content URL does not identify a workbook and a view.")
+ workbook = parts[0]
+ sheet = view.view_url_name or parts[-1]
+ server = self.parent_srv.server_address.rstrip("/")
+ site = self.parent_srv.site_url
+ view_path = f"{quote(workbook, safe='')}/{quote(sheet, safe='')}"
+ if site:
+ src = f"{server}/t/{quote(site, safe='')}/views/{view_path}"
+ site_root = f"/t/{site}"
+ else:
+ src = f"{server}/views/{view_path}"
+ site_root = ""
+ if self.parent_srv.check_at_least_version("3.14"):
+ script = f"{server}/javascripts/api/tableau.embedding.3.latest.min.js"
+ return (
+ f'\n'
+ f'