📌 Developers & APIs | Resources
Ciara Brennan (Tableau)
📌 Join the Tableau Developer Program and start learning how you can build on the Tableau Developer Platform to fit your organization's unique needs. You'll get everything you need to keep your skills sharp, including tutorials, webinars, the latest news, and even your own personal development site. You will also get access to thousands of DataDevs members for networking, troubleshooting, Q&As, and expert insights.
Amber Crowe (Member) asked a question.
We are using the Embedded API to display Tableau dashboards in a web portal. Our row level security is based on the username mapped to a customer ID in an entitlement table, so the user can only see their personal data.
For On-Demand Access (ODA), it looks like we don't have to provision users on our Tableau Server. Rather, access will be controlled on the web portal side, and the web portal can send user attributes to Tableau via the token.
With ODA are we still able to use our entitlement tables for RLS? Will it be secure? It's critical that our customers can not see other user's data.
Right now, our plan is:
For testing, we have my personal email hardcoded in the token under the "sub" as we needed a provisioned user to test the connection to our Tableau site. Can that be removed once everything is set up?
Best Answer
@Amber Crowe (Member)
Hi, everything seems right except the last step. Why?, according to the docs, the user attribute functions don't work with published data sources:
https://help.tableau.com/current/api/embedding_api/en-us/docs/embedding_api_user_attributes.html
So, I have not tested if this restriction still is active (you may test it). So, I recommend you to make three tests with:
a. Published data source (it may fail) which contains the lower([Customer]) = lower(USERATTRIBUTE("Username")) inside the data source in the data source filters section. (so you publish the datasource with this data source filter) -> It should not work.
b. A workbook connected to a published datasource, that has the relationship to your entitlement table but not the datasource filter published in the datasource. Instead, create the calc at the workbook level (lower([Customer]) = lower(USERATTRIBUTE("Username"))) and add it as a datasource filter from the workbook. -> It may work.
c. Test with an embedded data source in the workbook (so the relationship model belongs to the workbook) and create the user filter calc within the workbook and apply as a datasource filter -> This should work.
For testing, we have my personal email hardcoded in the token under the "sub" as we needed a provisioned user to test the connection to our Tableau site. Can that be removed once everything is set up?
It seems you may be using a Tableau Cloud site that does not have ODA and Usage Based Licensing activated, so I guess you are testing on this site without ODA and that is why you need to use the sub clause with an existing user. When moving to the ODA Tableau Cloud site, I recommend you to use still the sub JWT attribute, but with the username of the not provisioned user. If I remember, you may use USERATTRIBUTE("sub"). If the sub attribute is not accesible with userattribute, you may add another attribute to the JWT with the username.
e.g USERATTRIBUTE("username")
Also, you would need to pass the https://tableau.com/oda attribute in the JWT with the true value. (it can only be used with sites with ODA activated and usage based licensing).
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador
Bradley Service (Member) asked a question.
We are embedding a view in our application and need to programmatically change what filters are applied to the report before it loads on the page. I have been able to accomplish this using <viz-filter field="some" value="thing" /> for all filters except the date range filters. We've tried changing the filters to different styles (a Range of Dates slider filter and trying two Start Date -> End Date filters) and neither are effected by the values passed in on the viz-filter. Ideally, we should have it set up so that you can pass the viz an end date and it will change the start date relative to that value so that you're always looking at the same span of time (e.g. 4 weeks, 2 months, etc.).
I've checked for grammatical errors. I've tried downloading the tableau-api from npm and initializing the viz in a different way. The only method that I haven't tried successfully has been inserting the appyFiltersAsync() method because the documentation doesn't show you how to import tableau into a React Component, and I am unable to access it from the window property.
Any help would be greatly appreciated,
Thanks
Best Answer
@Bradley Service (Member)
Well, I have tested the if the <viz-parameter> option works. If you create a page with the following code, you will notice it works.
- <script type="module" src="https://public.tableau.com/javascripts/api/tableau.embedding.3.latest.min.js"></script>
-
- <tableau-viz id="tableauViz" src='https://public.tableau.com/views/EmbedAPIv3changingparametersExample/Dashboard1' toolbar="bottom" hide-tabs>
- <viz-parameter name="Start Date" value="2022-01-01"></viz-parameter>
- <viz-parameter name="End Date" value="2022-12-31"></viz-parameter>
- </tableau-viz>
The original workbook:
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador
Qasim Ali (Member) asked a question.
I've set up a dummy project with a server using node.js:
- const express = require("express");
- const jwt = require("jsonwebtoken");
- const cors = require("cors");
- require("dotenv").config();
- const { v4: uuidv4 } = require('uuid');
-
- const app = express();
- app.use(cors());
- app.use(express.json());
-
- const secretValue = process.env.PRIVATE_KEY;
- const clientId = process.env.CLIENT_ID;
- const secretId = process.env.ISSUER;
- const username = process.env.USERNAME;
- const tokenExpiryInMinutes = 1;
-
- const scopes = [
- "tableau:views:embed",
- "tableau:views:embed_authoring",
- "tableau:insights:embed",
- ];
- const kid = secretId;
- const iss = clientId;
- const sub = username;
- const aud = "tableau";
- const exp = Math.floor(Date.now() / 1000) + (tokenExpiryInMinutes * 60);
- const jti = uuidv4();
- const scp = scopes;
-
-
- app.post("/generate-token", (req, res) => {
- const payload = {
- iss,
- exp,
- jti,
- aud,
- sub,
- scp,
- };
- console.log(payload);
- console.log(secretValue);
-
- const token = jwt.sign(payload, secretValue, {
- algorithm: "HS256",
- header: {
- kid,
- iss,
- },
- });
- console.log(token);
- res.json({ token });
- });
-
- app.listen(5000, () => console.log("Server running on port 5000"));
And the frontend using React:
- import React, { useEffect, useState } from "react";
-
- function TableauEmbed() {
- const [token, setToken] = useState(null);
-
- const fetchToken = async () => {
- try {
- const response = await fetch("http://localhost:5000/generate-token", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- cache: "no-store",
- });
- const data = await response.json();
- setToken(data.token);
- } catch (err) {
- console.error("Error fetching token:", err);
- }
- };
-
- useEffect(() => {
- fetchToken();
- }, []);
-
- return (
- <div>
- <h1>Tableau Embedded Dashboard</h1>
- {token ? (
- <tableau-viz
- id="tableauViz"
- width="1000"
- height="1000"
- hide-tabs={false}
- touch-optimize={false}
- disable-url-actions={false}
- debug={false}
- src="LINK_HIDDEN"
- device="Desktop"
- toolbar="bottom"
- token={token}
- >
- </tableau-viz>
- ) : (
- <p>Loading...</p>
- )}
- </div>
- );
- }
-
- export default TableauEmbed;
It runs fine when I start the server, but as soon as I access the link via an incognito browser, I get one of two errors:
The same also occurs when I reload the page on just one instance after a while has passed.
What is the problem here?
Yasmeen Wilde (Member) asked a question.
Here is our use case: Users publish snowflake data source with oauth authentication method and then site admin will edit the published data source on the server to change the authentication method from oauth to username/password using a service account. Site admin will have to download the data source to desktop, change authentication method and then republish. This causes inconvenience to our self-service creators because they will have to rely on site admins to publish their data sources. All published data sources must use service account credential due to our compliance standards.
Deepika Navani (Member) asked a question.
Code I am using since I have a secrets.toml
- tableau_auth = TSC.PersonalAccessTokenAuth(
- st.secrets["tableau"]["token_name"],
- st.secrets["tableau"]["token_secret"],
- st.secrets["tableau"]["site_id"],
- )
- server = TSC.Server(st.secrets["tableau"]["server_url"], use_server_version=True)
- # server.add_http_options({'verify': False})
- server.auth.sign_in(tableau_auth)
Error that I get:
- tableauserverclient.server.endpoint.exceptions.FailedSignInError: Failed Sign In Error: 401001: Signin Error Error signing in to Tableau Server
- Traceback:
- File "/home/deepika/projects/dd-dashboard/pages/3_tableau_dashboard.py", line 13, in <module>
- server.auth.sign_in(tableau_auth)
- File "/home/deepika/.pyenv/versions/3.11.9/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 274, in wrapper
- return func(self, *args, **kwargs)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- File "/home/deepika/.pyenv/versions/3.11.9/lib/python3.11/site-packages/tableauserverclient/server/endpoint/auth_endpoint.py", line 84, in sign_in
- self._check_status(server_response, url)
- File "/home/deepika/.pyenv/versions/3.11.9/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 164, in _check_status
- raise FailedSignInError.from_response(server_response.content, self.parent_srv.namespace, url)
Can someone help me here?
Best Answer
@Deepika Navani (Member)
Hi, let's suppose your url site is https://prod-useast-b.online.tableau.com/#/site/mysite/home
What are you using as st.secrets["tableau"]["site_id"]. In this case, you should use mysite as the site content url
Also, I notice an extra comma in line 4, it should be:
- st.secrets["tableau"]["site_id"]
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador
Pardhasaradhi B (Member) asked a question.
We need to extract the schema and table information of tableau server datasources, either from the tableau repository(Postgresql) or using Postman APIs. We tried doing this with postman, but unfortunately, we are getting all the schemas and tables used for each datasources. Please find the code we used below.
Login: {{baseUrl}}/auth/signin
<tsRequest>
<credentials personalAccessTokenName="extractrefresh"personalAccessTokenSecret="{{personal_token_prod}}" >
<site contentUrl="Site_Name" />
</credentials>
<tsRequest>
=================================
Post:https://tableau.url.com/api/metadata/graphql
{
datasources(filter: { name:"Datasource_Name" }){
name
upstreamDatabases {
tables {
schema
name
}
name
}
}
}
Any recommendation would be greatly appreciated, weather it is related to table connections, Sql query for Postgresql, or any API that suits my requirement.
Jian Du (Member) asked a question.
Dear All,
I am a licensed user on the Tableau Server of my company, and I am the site Admin of one the sites.
I need to pull out the full list of all the schedules registered on the server.
I tried graphQL but failed.
I searched through the following page about graphQL RootTypeQuery, it seems that Schedule is not among the fields available for search. Does this mean there is no way to retrieve the schedule list via graphQL?
https://help.tableau.com/current/api/metadata_api/en-us/reference/query.doc.html
Best Regards,
Jian
Best Answer
@Diego Martinez (Member) Thank you very much, I will check REST API out.
Please check out our post with some tips on asking a question and how to help you get answers more quickly.
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.