Need Help Fetching Data with ReactJS

Hi all,

I am trying to hydrate my app with musicbrainz DB as a json file. When checking the console I get an error “You are not authorized to access this resource.”

How do I gain access? How do I make a user agent header with fetch API in React?

useEffect(() => {

fetch(‘https://musicbrainz.org/ws/2/release-group/3bd76d40-7f0e-36b7-9348-91a33afee20e?inc=genres+user-genres&fmt=json’)
.then(response => response.json())
.then(myJson => {
setData(myJson);
})
.catch(function(error){console.log(error);})

}, [])

Your call requests User-Genres, which are the genres the currently logged in user has set themselves. That means in order for this call to succeed the user needs to login, which would require you to implement oauth authentication.

But probably that’s not what you want, in this case don’t include the User-Genres inc parameter.

4 Likes