# Errors with Weather API

**URL:** <https://discourse.processing.org/t/errors-with-weather-api/8180>\
**Category:** Coding Questions\
**Created:** [February 6, 2019, 11:37pm UTC](https://discourse.processing.org/t/errors-with-weather-api/8180 "2019-02-06T23:37:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jadenfigger](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@jadenfigger](https://discourse.processing.org/u/jadenfigger)\
**Post date:** [February 6, 2019, 11:37pm UTC](https://discourse.processing.org/t/errors-with-weather-api/8180/1 "2019-02-06T23:37:12Z")

</div>

Im trying to draw a circle based on data from a weather api and when i try to draw the circle i keep getting an error. I don’t know how to fix the mistake so here is the code. If you know how to fix it could you please let me know.

```auto
let weather;

function setup() {
  createCanvas(400, 400);
  loadJSON('http://api.openweathermap.org/data/2.5/weather?zip=85248,us&units=imperial&appid=27b5b65946faf6311b0225a9c450b652', gotData, 'pjson');
}

function gotData(data) {
  weather = data;
}

function draw() {
  background(51);

  tempeture = weather.main.temp;
  console.log(tempeture);
}

```

---

<div class="post-metadata">

**Author:** ![Californ1a](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/californ1a/32/2648_2.png) [@Californ1a](https://discourse.processing.org/u/Californ1a)\
**Post date:** [February 7, 2019, 1:11am UTC](https://discourse.processing.org/t/errors-with-weather-api/8180/2 "2019-02-07T01:11:52Z")

</div>

First, `temperature` isn’t defined in the code you provided, make sure you include `let temperature;` at the top alongside `let weather;` (or `let weather, temperature;` to define both). That probably won’t throw an error though, so the error you’re most likely running into is that `weather` is still undefined on the first run through `draw()` because it hasn’t gotten the data yet (so trying to read `weather.main.temp` isn’t possible). You can solve that by making sure that `weather` has something in it before using it, like this:

```auto
if (weather) {
  tempeture = weather.main.temp;
  console.log(tempeture);
}

```

---

<div class="post-metadata">

**Author:** ![jadenfigger](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@jadenfigger](https://discourse.processing.org/u/jadenfigger)\
**Post date:** [February 7, 2019, 1:37am UTC](https://discourse.processing.org/t/errors-with-weather-api/8180/3 "2019-02-07T01:37:44Z")

</div>

That worked! thank you so much.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 7, 2019, 5:59am UTC](https://discourse.processing.org/t/errors-with-weather-api/8180/4 "2019-02-07T05:59:45Z")

</div>

> **[OpenWeatherMapJSON](http://bl.ocks.org/GoSubRoutine/5fbc03e019c53254a2ba7e7fd3318b45)**
>
> GoSubRoutine’s Block 5fbc03e019c53254a2ba7e7fd3318b45
