Resources

Using GraphQL to query Tableau Online Server

Written by Colleen Hayes | Jun 5, 2023 12:00:00 PM

Return to Resources

Recently, Continuus was hired by a client who uses Tableau Online Server to replace some of their published data sources with new versions built in Snowflake. As the consultant placed with this client, I began the project by making a list of data sources and prioritizing which to replace first. 

Some of these data sources had dozens of fields, leading me to wonder, “Do we really need all of these in the replacement data source?” But without a PostgreSQL database to query, and without budget for Tableau’s Data Management Add On, I was at a loss as to how we might find if each field was being used. 

I did a Google search and found several blog posts and tutorials pointing to the use of an API called GraphQL that will allow you to query your server’s metadata and essentially provide you with the same thing. 

To access it, first log into your Tableau Online server in a browser. Find the name of the data source you wish to query and copy it. (If you need to investigate several, you may want to paste each data source name into a Notepad document.) 

Then, in the address bar, delete everything in the URL after “tableau.com/” and replace it with “/metadata/graphiql/”. There will be two forward slashes in a row and the URL will look like this: 

https://prod-useast-b.online.tableau.com//metadata/graphiql/ 

Once you hit enter, you’ll be brought to a page showing you the API query canvas on the left and results from your API calls on the right. Initially, these will both be blank. 

 

There are many tutorials out there to help you build your query, which appears to be in some sort of JSON-related query language, but this one will give you all the fields included in the data source: 

query fields { 

  datasources (filter: {name: "Paste your data source name here"}) { 

    name 

    fields { 

name 

    } 

  } 

} 

 

Copying the results into Notepad will give you a key to work from. The goal now is to see if each of those fields is used in any workbooks. You can use something like this to list out all fields used in all workbooks by adding the data source name in the filter. You can go back and forth from your key to the results of this query to determine if each field is listed. 

query fields { 

  datasources (filter: {name: "Paste your data source name here"}) { 

    name 

    downstreamSheets { 

      workbook { 

        name 

        sheets { 

       name 

          datasourceFields { 

            name  

          } 

        } 

      } 

    } 

  } 

} 

 

If you want to be more specific, you can query to see if a workbook is using a particular field by adding another filter: 
 

query fields { 

  datasources (filter: {name: "Paste your data source name here"}) { 

    name 

    downstreamSheets { 

      workbook { 

        name 

        sheets { 

       name 

          datasourceFields (filter: {name: "FIELD NAME"}) { 

            name  

          } 

        } 

      } 

    } 

  } 

} 

 

I am certainly no expert in this API or its querying language, but these basic queries should get you started and potentially allow you to pare down the fields included in your data sources for better dashboard performance. Check out the articles linked to below for more detail as to how you might go adjusting your query to find what you need! 

 

Metadata api GraphQL query to fetch remote datasource information 
https://community.tableau.com/s/question/0D54T00000SSuaRSAT/metadata-api-graphql-query-to-fetch-remote-datasource-information-remote-columns 

 

Making Use of the Tableau Metadata API 
https://medium.com/@rhelenius/making-use-of-the-tableau-metadata-api-16b67e3abf5a 

 

Introduction to Tableau's Metadata API 
https://www.prosvetova.com/blog/2020-08-17-tableau-metadata-api