Reputation: 793
Looking at the docs for the Tableau web data connector it appears that I have to define the data schema before retrieving the data? Is it possible to retrieve the data from a REST API and then populate the schema from the REST response?
The use case is I have a REST API that I pass parameters to, and depending on the parameters the returned data schema will vary. The JSON response from the API includes a "schema" section which documents the schema section of the data portion of the json.
A simplified version of a JSON response here:
{
'fields': [{
'name': 'id',
'fieldType': 'int'
},
{
'name': 'name',
'fieldType': 'string'
},
{
'name': 'value',
'fieldType': 'long'
}],
'data': [{
'record1': {
'id': '1',
'name': 'larry',
'value': '1596429'
}
},
{
'record2': {
'id': '2',
'name': 'Curly',
'value': '5464767'
}
}]
}
The "schema" is defined in the "fields" section of the json, and the data is all in the "data" section, but the schema will change depending on the paramaters passed to the API.
I can't get this to work, and all the examples I've found seem to indicate that I need to define the schema and then retrieve the data, but if the returned data schema changes based on the submitted parameters that model falls apart quickly.
Is there a way to retrieve the data 1st and then define the schema dynamically based on the API's response data?
Upvotes: 0
Views: 271
Reputation: 191
There is nothing stopping you from pulling the data within your WDC's getSchema function. You can make a request at that stage, get the info you need from the "fields" object you get from your endpoint, parse it to match Tableau's requirement, and pass that in as the schema. You will still need to pull the data again in the getData function. You can either make a second request or you can store the data from your first request in a variable and pull from that instead. Do note, however, if you refresh the WDC and the schema has changed it can mess up any worksheets you've built on the data source.
Upvotes: 2