Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to return user favorites via Tableau REST API

Tags:

c#

tableau-api

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

like image 260
DDuffy Avatar asked Jan 04 '19 09:01

DDuffy


People also ask

Can Tableau make REST API calls?

Host a web page that has the necessary code to call the REST API. In your Tableau workbook, set up a data source and a dashboard with a worksheet that will call a URL action which will go to the web page. If desired, add a web page object in the dashboard for feedback or updates.

Can Tableau pull data from an API?

Hyper API. Automate your interactions with Tableau extract (. hyper) files. You can use the API to create new extract files, or to open existing files, and then insert, update, delete, or read data from those files.

What is Tablou?

Tableau Mobile: a free app for iPad, iPhone, Android tablet and mobile browsers, enabling users to author a dashboard once, then view or edit it anywhere, on any device.


2 Answers

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.

like image 89
Lennart Avatar answered Sep 22 '22 15:09

Lennart


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.

like image 28
DDuffy Avatar answered Sep 23 '22 15:09

DDuffy