DatAmine DatAmine - 4 months ago 70
JSON Question

Bad OData Format when accessing OData feed from Tableau 8.1

I have trouble connecting to an OData feed, as I get this error message :
"Bad OData Format. Make sure you are using a URL that points to a valid OData Source"

I can access the url in a browser (and I get the expected JSON response), and I can connect to the OData feed through Excel (Power Query).

Does anyone have a similar problem ? And what do you think is the problem ?

I am using Tableau 8.1 with Windows 8, and I am developping my OData service through ASP.NET Web API 2.

Answer

Tableau Version 9.0 still has this problem when using Web API OData, it's doing it because Tableau requires the data to be in XML format but does not send the Accept header to let the server know it.

Here's what worked for me. I modify this code(replacing YourDatabaseEntities and YourTable) and add it for each controller that Microsoft scaffolding creates :

/// <summary>
/// Class YourTableController.
/// </summary>
public class YourTableController : ODataController
{
    /// <summary>
    /// The database
    /// </summary>
    private YourDatabaseEntities db = new YourDatabaseEntities();
    /// <summary>
    /// Adds Accept header for Tableau which requires XML data but doesn't send a header requesting it
    /// </summary>
    protected void FTLP()
    {
        try
        {
            Request.Headers.Remove("Accept");
        }
        catch { }
        try
        {
            Request.Headers.Add("Accept", "application/atom+xml");
        }
        catch { }
    }
    // GET: odata/YourTable
    /// <summary>
    /// Gets the Your Table.
    /// </summary>
    /// <returns>IQueryable&lt;YourTable&gt;.</returns>
    [EnableQuery]
    public IQueryable<YourTable> GetYourTable()
    {
        FTLP();//Add this to Fix Tableau XML requirement 
        return db.YourTable;
    }

    // GET: odata/YourTable(5)
    /// <summary>
    /// Gets the YourTable.
    /// </summary>
    /// <param name="key">The key.</param>
    /// <returns>SingleResult&lt;YourTable&gt;.</returns>
    [EnableQuery]
    public SingleResult<YourTable> GetYourTable([FromODataUri] DateTime key)
    {
        FTLP();//Add this to Fix Tableau XML requirement 
        return SingleResult.Create(db.YourTable.Where(YourTable => YourTable.Date == key));
    }

///////