JSON API WebConnector for Tableau

After creating a tableau webconnector to extract data from an internal API, I used earthquakeUSGS.html as a reference (https://github.com/tableau/webdataconnector). The API responds with json data (see code below). Utilizing the "Web data connector simulator 2.0" was smooth until I encountered an issue with fetching table data. Being new to JavaScript, I suspect that my error lies in the script itself. To navigate through the data, I followed Korijn's advice on iterating through nested JSON object arrays on this post: https://stackoverflow.com/questions/15268594/iterate-through-nested-json-object-array

The Issue: It is likely related to the JavaScript iterator navigating over the json objects. If someone could review the json data (below) and examine my iterator, it would be greatly appreciated as this hurdle prevents me from successfully fetching the necessary data.

test.js

(function() {
    // Creating the connector object
    var myConnector = tableau.makeConnector();

    // Defining the schema
    myConnector.getSchema = function(schemaCallback) {
        var cols = [{
            id: "prog",
            alias: "PrognosisTime",
            dataType: tableau.dataTypeEnum.string
        }, {
            id: "start",
            alias: "Start",
            dataType: tableau.dataTypeEnum.date
        }, {
            id: "val",
            alias: "Value",
            dataType: tableau.dataTypeEnum.float
        }];

        var tableSchema = {
            id: "table",
            alias: "187",
            columns: cols
        };

        schemaCallback([tableSchema]);
    };

    // Data retrieval process
    myConnector.getData = function(table, doneCallback) {
        $.getJSON("http://myapi.com/119%2C7777/Flattened?start=today&end=today&timeZone=CET&asOf=now&aggregation=None", function(resp) {
            var feat = resp.features,
                tableData = [];
                tableData.push(
                    {"table":feat.properties.table}
                    );

            // Iterating over the JSON object
            //var SeriesId = feat.SeriesId
            for(var i = 0; i <feat.DataPoints.length; i++){
                var PrognosisTime = feat.DataPoints.PrognosisTime;
                var Start = feat.DataPoints.Start;
                var Value = feat.DataPoints.Value;
            }
            table.appendRows(tableData);
            doneCallback();
        });
    };

    tableau.registerConnector(myConnector);

    // Event listeners upon form submission by user
    $(document).ready(function() {
        $("#submitButton").click(function() {
            tableau.connectionName = "Neas"; // This will be the data source name in Tableau
            tableau.submit(); // Sends the connector object to Tableau
        });
    });
})();

json from API

[
  {
    "SeriesId": 119,
    "DataPoints": [
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T00:00:00",
        "Value": 26.19
      },
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T01:00:00",
        "Value": 23.9
      },
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T02:00:00",
        "Value": 22.82
      }
    ]
  },
  {
    "SeriesId": 7777,
    "DataPoints": [
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T00:00:00",
        "Value": 36.39
      },
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T00:15:00",
        "Value": 28.81
      },
      {
        "PrognosisTime": null,
        "Start": "2016-08-24T00:30:00",
        "Value": 24.28
      }
    ]
  }
]

Answer №1

Looks like the issue lies within this specific line:

let features = resp.features

The variable 'resp' is an array in your JSON data, and there isn't a key named 'features'. To resolve this, you can either iterate over 'resp' directly or assign 'resp' to another variable like 'feat' and extract the 'DataPoints' array from it.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to transfer data through Ionic popover

I've encountered an issue when trying to pass data to my popover component, as the data doesn't seem to be sent successfully. Code HTML <div class="message" id="conversation" *ngFor="let message of messages.notes"> <ion-row class= ...

How to format a Date object as yyyy-MM-dd when serializing to JSON in Angular?

I have a situation where I need to display an object's 'birthDate' property in the format DD/MM/YYYY on screen. The data is stored in the database as YYYY-MM-DD, which is a string type. I am currently using bootstrap bsDatePicker for this ta ...

Creating a private variable to perform a select_sum query

I have defined private variables in my CodeIgniter code like this: private $table = 'phone'; private $column_order = array(null, 'name', 'price'); private $type = array('type'); private $battery_consumption = array ...

Navigating with Vue.js using programmatic methods while passing props

I am working with a Vue component that includes a prop called 'title' like this: <script> export default { props: ['title'], data() { return { } } } </script> After completing a specific action, I need to pro ...

Enhancing User Experience with Load Indicator during State Changes in React Native

I'm facing an issue where the page for displaying a single item is loading slowly - I need to delay the page from loading until the object has changed. After checking the navigation params through console log, I can see that the id changes when each b ...

Accessing Rails controller information via a JavaScript AJAX request

In the process of developing a rails application, I have implemented code within the controller to interact with an API. Initially, I call the inventories endpoint, followed by separate calls to two other id endpoints (store_id and product_id) in order to ...

Generate a text input field within a dropdown menu

Below is an example of my basic HTML code for a drop-down list: <span id="Div_List"> <label for="Gender">For:</label> <select name="Gender" id="Sex"> <option value="1">1000mtr</option> <option val ...

Error code E11000 is thrown due to a duplicate key in a Node.js application

Whenever I input data on the webpage, it syncs correctly with the database. However, when I attempt to fill out the same form again, an error occurs: { "code": 11000, "index": 0, "errmsg": "E11000 duplicate key error collection: test.creates i ...

What is the process for transforming a list of strings into a JSON array using a shell command?

Is there a more efficient way to parse and convert a list of strings into a JSON string array using shell commands? '["test1","test2","test3"]' and output it as: test1 test2 test3 I have attempted the following method: string=$1 array=${string# ...

Using API calls to update component state in React-Redux

I am currently working on setting up a React application where clicking on a map marker in one component triggers the re-rendering of another component on the page. This new component should display data retrieved from a database and update the URL accordi ...

Tips for extracting parameters from a URL using Express JS in a custom manner

Recently, I set up a server using the express package and encountered an issue while trying to extract parameters from the URL in a specific format. The URL structure is as follows: (notice there's no '?' indicating parameters). I am lookin ...

Switching from AngularJS to vanilla JavaScript or integrating AngularJS and Flask on a single server

It is common knowledge that angular has the ability to create a project and convert it into pure HTML, CSS, and js code. Similarly, I am looking to do the same for my AngularJS application. When I execute the app using npm start it works perfectly fine. My ...

Adding local JavaScript to a Vue component is a great way to enhance its functionality

I am currently working on integrating a homepage concept (Home.vue) into my project. The design is based on a template that I purchased, which includes CSS, HTML files, and custom JavaScript. While most of the CSS has been successfully imported, I am havin ...

Encoding identification data from JSON using ColdFusion

Hello everyone, I've been puzzling over how to intercept and encrypt database record ID from a JSON request in ColdFusion. Below is the code I have so far, along with my unsuccessful attempt. Any assistance would be greatly appreciated. <cfquery ...

Creating a JQuery slider that efficiently loads and displays groups of elements consecutively

Currently, I am in the process of developing an infinite horizontal tab slider using jQuery. My main objective is to optimize loading time by having the slider display only the first 10 slides upon initial page load. Subsequent slides will be loaded as the ...

The anchor tag seems to be malfunctioning within the div container

<style type="text/css> .xyz { position: absolute; top: 120px; left: 160px; z-index: -1; } #container { position: relative; overflow: visible; opacity: .3; } </style> <body> <div> <video i ...

Alter the div's HTML content once the Ajax operation is completed

I have a div element that looks like this: <div class="progress" id="progress-bar"></div> I am using the following JavaScript code along with an ajax call to retrieve some data. The data returned is 0, however, the content is not being added ...

Utilizing ConfigurationBuilder to incorporate null values into a list using a json file

As I attempt to insert a list of enums into appsettings.json for later iteration in the code, I encounter an issue. When I include a null value in the list within the JSON file, it does not populate as a null value when loading the Settings from the file. ...

PHP exits the while loop unexpectedly

Recently delving into the world of PHP and encountering what I believe to be a peculiar issue. I have consolidated this file (originally spread across multiple functions) for testing purposes and to better articulate the problem at hand. The core of the p ...

The sequence of data and the final event triggered by http.createServer

const server = http.createServer(async (request, response) => { if (request.method === "POST") { var data = ""; request .on("data", async (chunk) => { console.log("1"); data + ...