9
votes

UPDATE: Sept 2019.

This API call now works as intended. Issues on the Tableau end appear to have been resolved and the call now returns the correct data.

===============================================================

I'm using the Tableau REST API via C# to try and get a list of users favorites. I know the user has some, because its me. 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/api http://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 = $@"{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?

(I have also posted the question on Tableau Forum.)

UPDATE:

I have included the CURL and Headers of the request, as well as the results, in the screenshots below. (I use 'Restlet Client' more than 'Postman' so screenshots are from the former.) ID's and authentication tokens have been removed as they are sensitive information, and i don't think my company would be happy with me putting them on the public facing internet. All ID's and auth keys are in the correct case and presented correctly. They are used in several other API calls with success and are pulled direct from Tableau via the API.

The exceptions, i have found out are the inability to find the version of the API that i am calling. so v2.6 - v2.8 and v3.0 all "work". Other versions return a 404001 VERSION_NOT_FOUND error.

enter image description here

enter image description here

2
I'm not familiar with C# strings but I don't see where in your function code you replace the bracketed values for Server, APIVersion, SiteID, and UserID in the url variable.Sam M
The word within the brackets is the variable itself and is set elsewhere in the code. SiteID, UserID, APIVersion, and AuthToken are all passed in as parameters. "public static string QueryFavourites(string APIVersion, string AuthToken, string SiteID, string UserID)"DDuffy
This may be the part that's throwing you. The bracketed values are the variables and are inserted with string interpolation (The $ sign before the string).DDuffy
Perhaps you should re-check if the information you supply is correct: for example try to craft the desired request in postman, and getting a desirable result before implementing it.Lennart
Tried postman. CURL runs fine, just returns no 'favorites' data (i.e. <favorites/> output should look like this). The information is good, Server, SiteID, and UserID are all used in other API calls with success. All other API calls are of similar structure to this one. Tableau API just seems to be a bit... touchy...DDuffy

2 Answers

5
votes

The approach i would take is:

  1. Query a user on the site. (the user that has the favorites)

  2. Check if the user is actually: the same user you are authenticated as; and the same user you are gonna query for favorites

  3. If they are the same, try adding a favorite with the REST API (DataSource, View or Workbook)

  4. Get the favorites for the user, the datasource/view/workbook you added as a favorite should be in there.

If you want to Update the user, Add user to site or Add user to Group, I've added links to the documentation

You can do these things with Postman/tool of your choice.

What you can also try is ensuring 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.

Hope this helps!

EDIT: Maybe you can try adding a new user with group regular to a site, ensuring that you are a member of the site too. Afterwards adding a favorite and getting the favorites for the user of group regular. If that doesnt work u can verify whether its impossible to get favorites for users of group regular as well, besides admins.

1
votes

Finally found out what was happening. It doesn't work as intended. It will only return user favorites for the user that is authenticated in the authentication token, regardless of what user id you put in the request. Had a call with Tableau support and accidentally figured it out, when we switched authenticated user. I will leave this here in case anyone else comes across the same issue.