Do you have an example you could share that I could use to replicate what you are experiencing?
I had a look at the documentation and did notice that using the web-interface “try it” option also resulted in 401 Unauthorized. For example, using the /data/wow/connected-realm/index
endpoint from Game Data APIs.
Following the advice from the linked posters above, I tried using a bearer token and was still getting the same issues, until I noticed that namespace is a required parameter and can be given as a Battlenet-Namespace header. Here’s a working example using NodeJS with the Axios package that may prove useful in your own troubleshooting:
const axios = require('axios');
const url = YOUR_URL;
const token YOUR_ACCESS_TOKEN;
axios.get(url, {
headers: {
'Authorization': `Bearer ${token}`,
'Region': 'us',
'Battlenet-Namespace': 'dynamic-us',
}
})
.then(resp => {
console.log(resp.data);
})
.catch(e => {
console.log('Error with request: ', e);
});
Obviously, you’ll want to replace YOUR_URL
and YOUR_ACCESS_TOKEN
with the relevant values. In this case, I used https://us.api.blizzard.com/data/wow/connected-realm/index
as the URL, and for my access token, I just generated it using the curl call from the documentation:
curl -u {client_id}:{client_secret} -d grant_type=client_credentials https:oauth.battle.net/token
Replacing {client_id}
and {client_secret}
with the values from an API Access Client from the developer portal (https://develop.battle.net/access/clients
).
Of potentially interesting note, adding the required headers to a curl request also seems to give the expected results…
curl -i -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Region: us" -H "Battlenet-Namespace: dynamic-us" -X GET https://us.api.blizzard.com/data/wow/connected-realm/index
# Additional Examples:
## get hunter pets
curl -i -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Region: us" -H "Battlenet-Namespace: profile-classic-us" -X GET https://us.api.blizzard.com/profile/wow/character/faerlina/snipy/hunter-pets
## get character equipment
curl -i -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Region: us" -H "Battlenet-Namespace: profile-classic-us" -X GET https://us.api.blizzard.com/profile/wow/character/faerlina/snipy/equipment
## specifying Era using classic1x
curl -i -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Region: us" -H "Battlenet-Namespace: profile-classic1x-us" -X GET https://us.api.blizzard.com/profile/wow/character/whitemane/astralarya/equipment