working with openweathermap api getting an unauthorized error

I need some help understanding why this api is not liking my format. getting the 401 error but I am giving the server the appid here is my code, thanks for the help!

       function getForecast(){
          var city = $("#city").val();
          var days = $("#days").val();
          var appID ='APIKEY';


    if(city != '' && days != ''){

        $.ajax({
        url: 'http://api.openweathermap.org/data/2.5/forecast/daily? 
         q='+city+'&units=metric&cnt='+days+'&APPID='+appID+'',
        type:"GET",
        dataType: "jsonp",

2 answers

  • answered 2018-10-09 17:20 whatapalaver

    Is it safe to assume that you have defined the actual 'APIKEY' somewhere such as your .env file?

    I might expect to see something like: var appID = process.ENV.APIKEY

    If you haven't declared the actual APIKEY anywhere first you need to get one from openweathermap and then I suggest you research Environment Variables so you know how to call them.

  • answered 2018-10-09 18:22 bowl_of_rice

    I figured out my issue. I was calling the api code wrong. instead of:

         http://api.openweathermap.org/data/2.5/forecast/daily? 
         q='+city+'&units=metric&cnt='+days+'&APPID='+appID+
    

    I needed to call this:

          http://api.openweathermap.org/data/2.5/forecast? 
           q=London,us&mode=json&appid
    

    Thanks anyways