Total beginner needs some help on using api

Hello,

I am a long time World of Warcraft player but a total noob currently learning node.js. I thought I would want to use World of Warcraft API to make web app.
I quickly read thru the guide Blizzard provided but found it was not easy to comprehend by myself. Where should I start?

Today, I tried to do http request to one of the API end point.

const character_profile = (name, server, callback) => {

   const url = `https://us.api.blizzard.com/profile/wow/character/${server}/${name}?namespace=profile-us&locale=en_US&access_token=mytoken`

   request( { url, json: true }, (error, response) => {

        if (error) {
            callback("Unable to connect to location ", undefined)
        } else {
            callback(undefined, response)
        }


    })


}


app.get("", (req,res) => {
const name = "mycharactername"
const server = "tichondrius"

character_profile(name, server, (error, response) => {

    if (error) {
        return console.log(error)
    } 

    console.log(response.body.name)
    console.log(response.body.race.name)
    console.log(response.body.character_class.name)
    
})


})

So I did retrieve some information from it but when I copy and pasted the value of “href” into browser, it didn’t work. Why?

I have no idea where I am going.
Any advice will be really helpful.
Thank you.
Sorry for being so noob and writing not so good English.

When you paste the href into the browser you’re not passing the token.

You need to make a GET request with the header “Authorization: Bearer {insert your token here}”.

I’d recommend using the application Postman, it’s free to download and allows you to easily test http requests.

1 Like

While the preferred way for passing the token is with a Bearer header like Elatar said, you can also just add your token to the end of the href URL like you did in your first request for testing purposes.

Also, you might consider using a community created library like https://github.com/benweier/blizzard.js for handling requests. The one I pasted here was last updated 2 months ago so I assume it is up to date with the newest changes.

Thank you for your help.
It seems working. I did like you told me with Postman.
It sends back some more Json data which I have no idea what to do with.
And also the access token I used yesterday didn’t work today so I had to get a new one by trying to access api end point here on the website.
Why did I need a new access token?
Sorry It feels like I am swimming in the ocean trying to find a raft.

The token expires after 24 hours, it’s normal to have to fetch a new one periodically.

Regarding the excess json data, which href did you use?

if it expires every 24 hours, I suppose there is a way that everybody does to automatically renew it everyday?

And I used this href.

…blizzard.com/profile/wow/character/tichondrius/charactername/pvp-summary?namespace=profile-us

I can’t upload link here so i omitted the first part of the endpoint.

Now I understand it’s more character information specifically about pvp.

So I am supposed to use all these extra hrefs to retrieve more info. correct?
And what’s the normal way to do api request?(without having to manually get token everyday)

Thank you so much.

Ideally you’ll have a job running to renew tokens on a schedule.

You only need to fetch the ones you need, sometimes it gives extra information. Also the link with the key _self is an alias to what you just requested. If you follow this you’ll fall in a loop.

In terms of automatically doing it, you need a job/schedule. In terms of code, you need to use a library or write your own. You can do without it, but if you repeat the same code all over the place, if something changes you have to chase and change it all.