openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

CORS errors on Partner API Single-request and Multi-request endpoints

Open BrentOates opened this issue 1 year ago • 4 comments

Calling the /volumes/brief endpoints using native Node.js fetch() results in CORS errors.

Evidence / Screenshot (if possible)

image

Relevant url?

Single GET - http://openlibrary.org/api/volumes/brief/isbn/0596156715.json Multi GET - http://openlibrary.org/api/volumes/brief/json/isbn:0596156715

Steps to Reproduce

The following snippet recreates the issue;

const OpenLibTest = async () => {
  (await fetch('http://openlibrary.org/api/volumes/brief/isbn/0596156715.json'))
    .json()
    .then((data) => {
      console.log(data);
    });
};
OpenLibTest();
  • Actual:
    • CORS error returned from API
  • Expected:
    • Data to be returned due to using specified JSON endpoints

Details

  • Logged in (Y/N)? N/A
  • Browser type/version? Chrome rendering Vue/Angular apps
  • Operating system? Windows 11 / macOS Ventura
  • Environment (prod/dev/local)? prod

Proposal & Constraints

I believe the endpoints may just need amending to follow the same logic as in https://github.com/internetarchive/openlibrary/issues/329 and https://github.com/internetarchive/openlibrary/issues/220

BrentOates avatar Jan 27 '24 23:01 BrentOates

I think you probably want to be using the openlibrary.org/search.json?q= API!

mekarpeles avatar Jan 29 '24 20:01 mekarpeles

@mekarpeles Ahh yup - multiple ISBNs working nicely with random example after some digging (Plus returns a much nicer range of data!): https://openlibrary.org/search.json?q=isbn:9780241575536+OR+isbn:0596156715&fields=title,isbn,author_name Happy to close this one then, though maybe worth a clarifying note on the documentation for the Partner API to clarify those aren't CORS friendly!

BrentOates avatar Jan 31 '24 22:01 BrentOates

is this issue still Relevant?

btwshivam avatar Feb 05 '24 19:02 btwshivam

@BrentOates Depending on what your goal is, this query might be a little more useful:

https://openlibrary.org/search.json?q=isbn:9780241575536+OR+isbn:0596156715&fields=key,title,author_name,editions,editions.title,editions.isbn

This fetches the edition-specific info about the ISBN as well :+1:

cdrini avatar Feb 05 '24 19:02 cdrini