# Help with JSON from API

**URL:** <https://forum.freecodecamp.org/t/help-with-json-from-api/130982>\
**Category:** General\
**Created:** [June 23, 2017, 2:46pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982 "2017-06-23T14:46:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielBruce](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@GabrielBruce](https://forum.freecodecamp.org/u/GabrielBruce)\
**Post date:** [June 23, 2017, 2:46pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982/1 "2017-06-23T14:46:36Z")

</div>

I’m having some trouble retrieving a random quote from an API for my random quote generator. Could anybody point out what I’m doing wrong or provide any tips? Should I be using a different API?

I’m using this API: [https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en](https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en)

Here’s a link to my test CodePen: [https://codepen.io/gabrielbruce/pen/qjXPzg](https://codepen.io/gabrielbruce/pen/qjXPzg)

Here’s the pasted code (from a button press)

$(document).ready(function() {  
$("#new-quote").on(“click”, function(){  
$.getJSON(“[https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en](https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en)”, function(json) {  
$(“div”).html(json.quoteText);  
});  
});  
});

---

<div class="post-metadata">

**Author:** ![fortMaximus](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fortmaximus/32/50137_2.png) [@fortMaximus](https://forum.freecodecamp.org/u/fortMaximus)\
**Post date:** [June 23, 2017, 3:21pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982/2 "2017-06-23T15:21:29Z")

</div>

If you check the browser console, you have a CORS error (you can google the error in the console for more info).

I usually solve it by adding `?callback=?` at the end of the API URL. But it seems for this API, you have to do it like this `https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?`, which should achieve the same result as `callback=?` (which converts the request to jsonp).

---

<div class="post-metadata">

**Author:** ![GabrielBruce](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@GabrielBruce](https://forum.freecodecamp.org/u/GabrielBruce)\
**Post date:** [June 23, 2017, 3:34pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982/3 "2017-06-23T15:34:56Z")

</div>

Thank you so much!

I was starting to get a bit frustrated because it seemed like I had everything right. Now I’m off to read up on JSONP. Is this covered further in FCC?

20 internet points for you!

---

<div class="post-metadata">

**Author:** ![fortMaximus](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fortmaximus/32/50137_2.png) [@fortMaximus](https://forum.freecodecamp.org/u/fortMaximus)\
**Post date:** [June 23, 2017, 3:40pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982/4 "2017-06-23T15:40:47Z")

</div>

> [@GabrielBruce](#):
>
> Is this covered further in FCC?

No.

When something goes wrong, be sure to check the browser console and google any errors you see.

---

<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 17, 2021, 8:55pm UTC](https://forum.freecodecamp.org/t/help-with-json-from-api/130982/5 "2021-01-17T20:55:24Z")

</div>


