Using JavaScript fetch to get publicly available page from Discourse into an external site (Discourse API)

Continuing the discussion from The purpose of the 2 Discourse API systems:

What if we want to make a request for a publicly available info on the Discourse instance into another publicly open site?

For example, this page (https://meta.discourse.org/u/gassim.json) is available for the public to view directly without logging into meta.discourse.org instance, and I want to create a react app that will pull this request using fetch and will display it on another publicly available site (a page that doesn’t require login details.) What API should I use? Admin API would’ve have worked perfectly given the fact I can generate a ‘get’ api key that’s restricted only for one type of request, but reading from several posts, Admin API isn’t allowed for JavaScript clients. On the other hand, the User API seems to want the users to ‘enable’/login for it to work on the external page but we just want to display publicly available information without the need for any login.

Further clarification is much appreciated and needed please! And if possible, I would appreciate if you know a working example that you could share similar to the use case mentioned at the top of my post.

Thanks in advance!

If you want data that is available without logging in, your don’t need to use an API key.

4 Likes

Thank you @pfaffman! This solves the issue. I was adding the API key headers and it’s what caused the errors to show up, but after removing the API keys and doing a regular fetch request it worked. :+1::+1:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.