Hello,
I’m having issues trying to get the token prize from the API.
I keep getting the 403 forbidden status and I think I’m doing the correct OAuth flow to obtain the access token because I do it on another project and it works just fine.
Trying it in the webpage doesn’t give me any problem.
Here is my code.
getToken().then(token => {
console.log(token)
getWowTokenPrize(token)
})
async function getToken() {
let key = 'clientid'
let secret = 'clientsecret'
let response = await fetch('https://eu.battle.net/oauth/token', {
method: 'POST',
body: 'grant_type=client_credentials&client_id=' + key + '&client_secret=' + secret,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'cache-control': 'no-cache'
}
})
let json = await response.json()
return json.access_token
}
async function getWowTokenPrize(accessToken){
let response = await fetch('https://eu.api.blizzard.com/data/wow/token/index', {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'cache-control': 'no-cache',
'Authorization': 'Bearer ' + accessToken,
'Battlenet-Namespace': 'dynamic-eu'
}
})
console.log(response)
let json = await response.json();
console.log(json)
}