# API call didn't work

**URL:** <https://forum.freecodecamp.org/t/api-call-didnt-work/106063>\
**Category:** General\
**Created:** [April 14, 2017, 8:18pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063 "2017-04-14T20:18:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![avi-jkiapt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/avi-jkiapt/32/67874_2.png) [@avi-jkiapt](https://forum.freecodecamp.org/u/avi-jkiapt)\
**Post date:** [April 14, 2017, 8:18pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/1 "2017-04-14T20:18:08Z")

</div>

Hello , my api call didn’t work. here is js

```javascript
$(function(){
var C=false;
var apiData;
backgroundImg=['https://cdn.pixabay.com/photo/2016/06/13/22/12/flash-1455285_960_720.jpg',
' https://cdn.pixabay.com/photo/2013/12/09/13/45/waterfall-225961_960_720.jpg',
'http://images.all-free-download.com/images/graphiclarge/drops_rain_glass_220210.jpg','http://wallpaper-gallery.net/images/snow-wallpapers/snow-wallpapers-1.jpg','http://images.all-free-download.com/images/graphiclarge/winter_fog_200960.jpg','https://previews.123rf.com/images/tolokonov/tolokonov1208/tolokonov120800059/14889692-Sky-and-ocean-Abstract-natural-backgrounds-Stock-Photo.jpg','https://cdn.pixabay.com/photo/2015/12/25/13/03/sky-1107579_960_720.jpg'

]
function displayTemp(F,C){
if(C)
return Math.round((F-32)*(5/9)) +'° C';
return Math.round(F) +'° F';

}

$.getJSON('https://freegeoip.net/json/').done(function(location){

// console.log(location);
$('#country').html(location.country_name);
$('#city').html(location.city);
$('#latitude').html(location.latitude);
$('#longitude').html(location.longitude);

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat='+location.latitute+'&lon='+location.longitude+'&units=imperial&appid=d99414c365ff0845c676431520203ea0', function(data){

apiData=data;
console.log(apiData);
})
})

})

```

Can anyone help me please?

thanks in advance

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [April 14, 2017, 8:31pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/2 "2017-04-14T20:31:04Z")

</div>

I cleaned up your code.  
You need to use triple backticks to post code to the forum.  
See [this post for details](http://forum.freecodecamp.com/t/forum-code-formatting/25574).

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [April 14, 2017, 9:19pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/3 "2017-04-14T21:19:50Z")

</div>

Hi,

I found two problems. First, JQuery isn’t loaded (maybe you loaded it in your html.)

The other problem is that you mispelled “latitude” in your url (_location.latitute_). I discovered this by consoling the whole url string to the console so I could see what it was producing and saw that the string contained “…lat=undefined…”.

---

<div class="post-metadata">

**Author:** ![avi-jkiapt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/avi-jkiapt/32/67874_2.png) [@avi-jkiapt](https://forum.freecodecamp.org/u/avi-jkiapt)\
**Post date:** [April 15, 2017, 5:01am UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/4 "2017-04-15T05:01:21Z")

</div>

thankyou, this is my first post so i didn’t understand…

---

<div class="post-metadata">

**Author:** ![avi-jkiapt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/avi-jkiapt/32/67874_2.png) [@avi-jkiapt](https://forum.freecodecamp.org/u/avi-jkiapt)\
**Post date:** [April 15, 2017, 5:16am UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/5 "2017-04-15T05:16:28Z")

</div>

I have loaded jquery. Yes i have mispelled , (thank you for pointing it) but i corrected it and checked again but it is not working .  
Here is my link of codepen

> **[jmEbVa](https://codepen.io/avi-jkiapt/pen/jmEbVa)**
>
> ...

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [April 15, 2017, 6:10am UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/6 "2017-04-15T06:10:26Z")

</div>

What is not working?

When I run your pen, I get the correct data object in my console.

I have to make sure we’re clear - you know to check the console, right? I ask because there are a lot of beginners here that aren’t clear on things like this. There are two consoles - one in your browser (cntrl-shift-j to reach mine in Chrome) and one in the codepen program, at the bottom of the screen.

If you’re not getting that data object in your console, then I’m not sure what the problem is.

---

<div class="post-metadata">

**Author:** ![avi-jkiapt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/avi-jkiapt/32/67874_2.png) [@avi-jkiapt](https://forum.freecodecamp.org/u/avi-jkiapt)\
**Post date:** [April 15, 2017, 8:12am UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/7 "2017-04-15T08:12:50Z")

</div>

I am not getting data object in my console.  
i am checking in codepen console . It does not show anything.when i run there is nothing on console.  
I have also check on chrome console. It gives the error

Mixed Content: The page at ‘[https://codepen.io/avi-jkiapt/pen/jmEbVa?editors=0011](https://codepen.io/avi-jkiapt/pen/jmEbVa?editors=0011)’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘[http://api.openweathermap.org/data/2.5/weather?lat=26.4667&lon=80.35&units=imperial&appid=d99414c365ff0845c676431520203ea0](http://api.openweathermap.org/data/2.5/weather?lat=26.4667&lon=80.35&units=imperial&appid=d99414c365ff0845c676431520203ea0)’. This request has been blocked; the content must be served over HTTPS.

Can you tell what i do?

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [April 15, 2017, 4:32pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/8 "2017-04-15T16:32:18Z")

</div>

OK, I wish you’d included that error message in your original post.

There can be problems when you call an _http_ (unsecured) resource from an _https_ (secured) resource.

I believe the problem is that you are calling _ **http** ://api.openweathermap.org_ from _ **https** ://codepen.io_. I think if you switch one of those, your problem will be solved.

---

<div class="post-metadata">

**Author:** ![avi-jkiapt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/avi-jkiapt/32/67874_2.png) [@avi-jkiapt](https://forum.freecodecamp.org/u/avi-jkiapt)\
**Post date:** [April 15, 2017, 4:52pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/9 "2017-04-15T16:52:14Z")

</div>

okay, I got it. It working thank you so much from bottom of my heart. Thanks a lot…

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [April 15, 2017, 8:25pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/10 "2017-04-15T20:25:24Z")

</div>

hey, that’s what we do here. Pretty soon you’ll be helping someone with the same problem.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 6:01pm UTC](https://forum.freecodecamp.org/t/api-call-didnt-work/106063/11 "2021-01-16T18:01:59Z")

</div>

Closed on January 16, 2021, 6:01pm UTC


