I am new to Javascript so maybe my question is common knowledge to some.
I think I did everything required to access PUBG api, but I am always getting error, response.ok is always false I think.
here is my code:
const apiKey = "key-example";
const apiUrl = "https://api.pubg.com/shards/steam"
fetch(apiUrl, {
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/vnd.api+json",
},
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(protectedData => {
// Process the protected data
console.log('Protected Data:', protectedData);
})
.catch(error => {
console.error('Error:', error);
});
And I always get “Network response was not ok” error. I tried to put “Authorization” and “Accept” properties as string, but same thing. Is there something else I’m missing here? Thank you.
I dont know what to try anymore
Jasmin Mujcinovic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.