# Problem fetching data from API with fetchp — possible CORS issue

**URL:** <https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912>\
**Category:** Help\
**Created:** [August 10, 2022, 8:40pm UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912 "2022-08-10T20:40:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![melaniewalsh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/melaniewalsh/32/3842_2.png) [@melaniewalsh](https://talk.observablehq.com/u/melaniewalsh)\
**Post date:** [August 10, 2022, 8:40pm UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/1 "2022-08-10T20:40:18Z")

</div>

I’m trying to pull data from the Goodreads API in one of my Observable notebooks: [The Goodreads Classics Sortable Table / Melanie Walsh / Observable](https://observablehq.com/@mellymeldubs/the-goodreads-classics-sortable-table/2). Previously I used Alec Glassford’s [soFetch](https://observablehq.com/@alecglassford/so-fetch) to get around CORS issues with the Goodreads API, but it doesn’t seem to be working anymore…

So now I’m trying to use @tomlarkworthy’s fetchp ([CORS Proxy fetchp / Tom Larkworthy / Observable](https://observablehq.com/@tomlarkworthy/fetchp)), but I can’t quite figure out how to make it work.

Does anybody have advice about how I can use fetchp to get Goodreads data from the API? Thank you!

 ![Screen Shot 2022-08-10 at 1.38.45 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/3/347b4bd3be76d08cc505138c6c4214cd0e87d2dd.png)

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [August 10, 2022, 9:07pm UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/2 "2022-08-10T21:07:44Z")

</div>

have you made the notebook public? unlisted is fine.

instead of calling .json() where the response is failing to parse as JSON, you can call .text() to debug.

I beleive it is printing out the error message found on this line [webcode.run/index.mjs at main · endpointservices/webcode.run · GitHub](https://github.com/endpointservices/webcode.run/blob/main/index.mjs#L373)

which is `Deployment '${req.requestConfig.name}' not found, did you remember to publish your notebook, or is your deploy function slow?`

i.e. your notebook is not publically accessible (requirement for fetchp and all webcode serverless endpoints unless you are a PRO customer)

---

<div class="post-metadata">

**Author:** ![melaniewalsh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/melaniewalsh/32/3842_2.png) [@melaniewalsh](https://talk.observablehq.com/u/melaniewalsh)\
**Post date:** [August 11, 2022, 12:35am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/3 "2022-08-11T00:35:42Z")

</div>

Thanks so much for your reply! Yeah the notebook is published, which is one of the reasons I’m confused about the error message: [The Goodreads Classics Sortable Table / Melanie Walsh / Observable](https://observablehq.com/@mellymeldubs/the-goodreads-classics-sortable-table/2)

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [August 11, 2022, 5:05am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/4 "2022-08-11T05:05:49Z")

</div>

OK you seem to have hit a bug. I forked your notebook and it works [The Goodreads Classics Sortable Table / Tom Larkworthy / Observable](https://observablehq.com/d/514ae110f9c800aa) (I removed the mode:cors bit)  
~~  
For performance, the server caches your notebook, but for whatever reason, the cached result is broken. I am building the tools to diagnose this issue better, but I don’t have good visibility why yet.~~

~~publishing an update to your notebook should fix the issue, as the cache is cleared every change. So maybe remove the mode: cors bit and republish, wait 2 mins and see if it works.  
~~

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [August 11, 2022, 5:13am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/5 "2022-08-11T05:13:17Z")

</div>

NO!!! IT’S THE URL, get rid of the 2nd slash, I don’t think my server can decode this form. I did not know observable did this.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/4/4eece3af7bf8126274f6c3441e2171e4367a22ae.png)

EDIT:

TIL: URLS can contain optional forward slash suffixes. Issue filed [endpoints in notebooks with training slashes in URL don't work · Issue #5 · endpointservices/webcode.run · GitHub](https://github.com/endpointservices/webcode.run/issues/5)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/f/f651a9a3129c10e3e74e6ff62a14432a919ed513.png)

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [August 11, 2022, 8:05am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/6 "2022-08-11T08:05:56Z")

</div>

The issue is fixed, you can not use /2 as a suffix, but you need to update the fetchp dependency to get the bugfix by clicking the padlock icon on the far right in the image below and clicking updateAll

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/9/95c1110af3bea7512b2cf0f50b0a80e646b2266e.png)

Observable documentation on version locking explaining why fetchp will no longer autoupdate on a bugfix: [Version Locking for Notebook Imports / Observable / Observable](https://observablehq.com/@observablehq/version-locking-for-notebook-imports)

---

<div class="post-metadata">

**Author:** ![melaniewalsh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/melaniewalsh/32/3842_2.png) [@melaniewalsh](https://talk.observablehq.com/u/melaniewalsh)\
**Post date:** [August 12, 2022, 3:49am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/7 "2022-08-12T03:49:49Z")

</div>

> [@tomlarkworthy](#):
>
> The Goodreads Classics Sortable Table / Tom Larkworthy / Observable

Oh my gosh, thank you so much for looking into this bug and for providing a fix! The notebook works perfectly now! I’m very grateful. This has been bothering me for weeks, and I can finally rest easy now

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [August 12, 2022, 4:05am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/8 "2022-08-12T04:05:16Z")

</div>

Thanks for raising the issue! Get in touch much sooner next time, I am here to help! (I could help with hiding your API key if you wish)

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [August 13, 2022, 8:13am UTC](https://talk.observablehq.com/t/problem-fetching-data-from-api-with-fetchp-possible-cors-issue/6912/9 "2022-08-13T08:13:29Z")

</div>

> [@tomlarkworthy](#):
>
> I did not know observable did this.

Here’s the slug part of the [regex](https://observablehq.com/@mootari/notebook-input#regIdentifier) that I use in [Notebook Input](https://observablehq.com/@mootari/notebook-input) to parse notebook identifiers:

```plaintext
@(?<user>[0-9a-z-_]{2,})\/(?<slug>[0-9a-z-_]{1,}(?:\/\\d+)?)

```

I’m very confident that I’ve considered all constraints here.
