3

The new NOAA api says that I need to put a token in the header for me to send request and it is giving me a token required error without it. I entered my email and received a token, but I am unsure on how to put it in a format that I can get a response.

Is there a way I can get a JSON response by posting all the information in the URL or do I need to make a html/php page? If I do need to create a web page, is there a library I can import that will allow me to get the JSON in java without the need for a webpage?

Mnoi
  • 45
  • 7
  • this page also mentions about hot to put up the token. How are you calling the service? – Guanxi Jun 01 '15 at 20:47
  • Well that's what I am unsure about; where does the header information go? In the past APIs I used, I could format the url so that it displayed the JSON test on a webpage. If I could get a response on the webpage, I can proceed on my own. – Mnoi Jun 01 '15 at 21:11
  • This cannot be updated by formatting the url. You need to create a web request. make use of jquery ajax call to update the request headers. http://api.jquery.com/jQuery.ajax/ – Guanxi Jun 02 '15 at 12:41
  • Thanks, I will look into that more, I didn't know where to start with this authentication stuff. – Mnoi Jun 03 '15 at 13:40

1 Answers1

0

you do not need to import any library for accessing NOAA-API you can directly call it using token.

you will have to add your token in header if you are calling it through AJAX call.

open:- http://js.do/ 1.add a script

Run this code using your token value.

<script>
function testjson(){
    //alert("inside testjson");
    jsontest = $.ajax({
        type: 'GET',
        url:  'https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCND&locationid=ZIP:28801&startdate=2010-05-01&enddate=2010-05-01',

//you can use different data-set values.
   headers: {
    Token: 'provide your token here'//example:'kxhfoJOtnEuxSNnMGMMSEITkmcsAFmFT'
        },
      //  async: false,
        dataType: 'json',
        success: function (data) {
            //Do stuff with the JSON data
            alert(JSON.stringify(data));
            jsontest = data;
            console.log("data is: " + data);
        },failure: function(){
            alert("ajax failed");
        }
    });
    console.log(jsontest);  
    //console.log(jsontest[0]);
}

testjson();
</script>