Accessing user data from a Discourse Forum API

AI-generated summary

EReeeN1208 is trying to access user data from a Discourse Forum API using Nextjs and TypeScript. They are attempting to fetch the data from https://www.chiefdelphi.com/u/ereeen1208/summary.json but are encountering CORS policy errors. They have tried using fetch() and axios.get() with different modes (no-cors and cors) but are still unable to retrieve the data. Lilly suggested a possible solution in the form of a link to a Discourse Meta discussion about CORS issues with JavaScript frontends: https://meta.discourse.org/t/cors-issue-with-javascript-frontend/158039/2?u=lilly.

Hello, I want to access the user data (summary.json) located at https://www.chiefdelphi.com/u/ereeen1208/summary.json using Nextjs typescript for a project. (chiefdelphi is a discourse forum for FRC) I’ve tried using multiple methods but each method results in an error or is unsuccessfull:

(In all examples, url = “https://www.chiefdelphi.com/u/ereeen1208/summary.json”)

Code that returns empty response:

const response = await fetch(url, {
            mode: "no-cors",
            method: "GET"
        })

Code that returns cors errors:

const response = await fetch(url, {
            mode: "cors",
            method: "GET"
})
const { data } = await axios.get(url);

Error for fetch():

Access to fetch at ‘https://www.chiefdelphi.com/u/ereeen1208/summary.json’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

Error for axios.get():

Access to XMLHttpRequest at ‘https://www.chiefdelphi.com/u/unpicasso/summary.json’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

What can I do to get the data from this url? Would I need to try a different web scraping method or add more parameters? Thanks.

hi @EReeeN1208 perhaps this might help?