0 votes
1 view
in BI by (14.5k points)
reshown by

I'm using the Tableau REST API via C# to try and get a list of user's favorites. I have tried using API Version 2.8,3.0, 3.1 and 3.2 with little to no joy. 2.8 and 3.0 respond with:

<?xml version='1.0' encoding='UTF-8'?>

<tsResponse xmlns="http://tableau.com/api"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://tableau.com/apihttp://tableau.com/api/ts-api-2.8.xsd"> //3.0.xsd when using API Version 3.0

     <favorites/> //There should be a plethora of favorites of all varieties in here.

</tsResponse>

3.1 and 3.2 give me a (404) Not found.

The code I have in c# is:

public static string QueryFavourites(string APIVersion, string AuthToken, string SiteID, string UserID)

    {

        string result = "";

        try

        {

            string url = [email protected]"{Server}/api/{APIVersion}/sites/{SiteID}/favorites/{UserID}";

            // Create the web request 

            WebRequest request = WebRequest.Create(url) as WebRequest;

            request.PreAuthenticate = true;

            request.Headers.Add($"x-tableau-auth: {AuthToken}");

            // Get response 

            using (WebResponse response = request.GetResponse())

            {

                // Get the response stream 

                StreamReader reader = new StreamReader(response.GetResponseStream());

                // Read the whole contents and return as a string 

                result = reader.ReadToEnd();

            }

            return result;

        }

        catch(Exception E)

        {

            logger.Error("Error! System Says: " + E.Message);

            return result;

        }

    }

I know the method works, as it is used for multiple other API calls using a different URL for each (depending on the call). Does anyone know if its an issue on the tableau end or on my end? Apparently, it should work with Tableau server 2.8 or above, which we have. (i think we're running 2018.1)

Is anyone able to get a list of favorites for a user using tableau REST API? Where am I going wrong?

1 Answer

0 votes
by (39.9k points)

Step 1: Query a user on the site. Refer to the following link for more details: https://onlinehelp.tableau.com/v2018.1/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Query_User_On_Site%3FTocPath%3DAPI%2520Reference%7C_____70 

Step 2: Check if the user is the same which you are authenticated as; and the same user has to query for favorites

Step 3: Try adding a favorite with the REST API (DataSource, View or Workbook)

Step 4: Get the favorites for the user, the data source/view/workbook you added as a favorite which should be present. Refer to the following link for more details: https://onlinehelp.tableau.com/v2018.1/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Get_Favorites_for_User%3FTocPath%3DAPI%2520Reference%7C_____48 

  • If you want to Update the user, Add user to site or Add user to Group, these are the links for getting documentation.

  • These things can also be done with Postman/tool of your choice.

  • You have to ensure the user that is querying another user (or the same) is a server admin (just to be safe), and making sure that you are a member of the same site of another (or the same) user.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...