openweathermap api invalid api key error [error401]

I am facing a problem dealing with openweathermap api, the api call is working perfectly in the browser but when use it in the project I get error401 which is referred here like this:
enter image description here

I have none of the problems listed in it

also here’s the link:,us&appid=####

works perfectly in the browser

enter image description here

and here’s my app.js:

/* Global Variables */
let baseURL = '';
let apiKey = ',us&appid=####';

// Create a new date instance dynamically with JS
let d = new Date();
let newDate = d.getMonth()+'.'+ d.getDate()+'.'+ d.getFullYear();

document.getElementById('generate').addEventListener('click', performAction);

function performAction(e){
  const temperature =  document.getElementById('zip').value;
  const userResponse = document.getElementById('feelings').value;
  const getTemp = async (baseURL,temperature,apiKey)=>{
      const res = await fetch(baseURL+temperature+apiKey)
    try {

    const data=await res.json();
    return data;
    }  catch(error) {
    console.log("error", error);
    // appropriately handle the error
   getTemp(baseURL+temperature+apiKey).then( res =>{ console.log(res);
    postData('/add', {temperature: temperature, date: newDate, userResponse: userResponse});

when I console.log() the url it works perfectly, yet the error appears in the get request:
enter image description here

11 thoughts on “openweathermap api invalid api key error [error401]”

Leave a Comment