Problem fetching data from API with fetchp — possible CORS issue

I’m trying to pull data from the Goodreads API in one of my Observable notebooks: The Goodreads Classics Sortable Table / Melanie Walsh / Observable. Previously I used Alec Glassford’s soFetch 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), 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!

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

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)

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

OK you seem to have hit a bug. I forked your notebook and it works The Goodreads Classics Sortable Table / Tom Larkworthy / Observable (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.

1 Like

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.

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

1 Like

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

Observable documentation on version locking explaining why fetchp will no longer autoupdate on a bugfix: Version Locking for Notebook Imports / Observable / Observable

1 Like

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

1 Like

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)

1 Like

Here’s the slug part of the regex that I use in Notebook Input to parse notebook identifiers:

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

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

1 Like