0 Replies Latest reply on Oct 16, 2018 11:42 AM by Stephen Crocker

    Getting Data from NOAA but having issues

    Stephen Crocker

      I'm using postman to get my connection tested with the api connection since I need a key to obtain the data. When I console.log the response I get the information, when I try to iterate over the JSON I'm getting a feat not defined but I have it in the data

       

      here is the entire .js <minus the token:   Anyone see anything wrong with this?  Also here is the error I'm getting from the Simulator

       

       

      (function () {

       

         //1: ******************************

         // Create the connector object

         var myConnector = tableau.makeConnector();

        

         //2: ******************************

         // Define the Schema

        myConnector.getSchema = function(schemaCallBack){

         var cols = [{

         id: "date",

         dataType: tableau.dataTypeEnum.date

        }, {

         id: "datatype",

         dataType: tableau.dataTypeEnum.string

        }, {

         id: "station",

         dataType: tableau.dataTypeEnum.string

        }, {

         id: "value",

         dataType: tableau.dataTypeEnum.int

        }];


         var tableSchema = {

         id: "WeatherData",

         columns: cols

        };


         schemaCallBack([tableSchema]);

        };


         //3: ******************************

         // Fetch and Download the data

         // ******************************

        myConnector.getData = function(table, doneCallback) {

         var settings = {

         "async": true,

         "crossDomain": true,

         "url": "https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&datatypeid=PRCP,TMAX,TMIN&startdate=2018-10-01&enddate=2018-10-30&limit=1000",

         "method": "GET",

         "headers": {

         "token": "<token here>"

        }

        };


         $.ajax(settings).done(function (resp) {

         console.log(resp);

         var feat = resp.value,

         tableData = [];


         // Iterate over the JSON object <Change the below block>

         for (var i = 0, len = feat.length; i < len; i++) {

        tableData.push({

         "date": feat[i].date,

         "datatype": feat[i].datatype,

         "station": feat[i].station,

         "value": feat[i].value

        });

        }

        


        table.appendRows(tableData);

         doneCallback();


        });

        };

         //4: *************************************

        tableau.registerConnector(myConnector);


         //5: ***************************************************

         // Create event listeners for when the user submits the form

         $(document).ready(function () {

         $("#submitButton").click(function () {

        tableau.connectionName = "WeatherData"; // This will be the data source name in Tableau

        tableau.submit(); // This sends the connector object to Tableau

        });

        });

      })();