JavaScripting

The definitive source of the best
JavaScript libraries, frameworks, and plugins.


  • ×

    Blizzard.js

    A promise-based Node.JS library for the Blizzard Battle.net Community Platform API
    Filed under  › 

    • 🔾25%Overall
    • 105
    • 3.4 days
    • 🕩23
    • 👥6

    Blizzard.js

    Travis Codecov Greenkeeper badge Gitter

    Blizzard.js is a promise-based Node.js library for the Blizzard Community Platform API.

    Install

    Install blizzard.js and save to your package.json dependencies in one easy step:

    With npm:

    $ npm install blizzard.js --save
    

    With yarn:

    $ yarn add blizzard.js
    

    Usage

    Step 1: require() and initialize() Blizzard.js within your application:

    const blizzard = require('blizzard.js').initialize({
      key: BLIZZARD_CLIENT_ID,
      secret: BLIZZARD_CLIENT_SECRET,
      origin: 'us', // optional
      locale: 'en_US' // optional
      token: '' // optional
    });
    

    Step 2: Fetch an API token, if one was not provided to intialize. You may prefetch a token however you like as documented by Client Credentials Flow

    blizzard.getApplicationToken()
      .then(response => {
        blizzard.defaults.token = response.data.access_token
      });
    

    Step 3: Call the API methods to request data:

    blizzard.wow.character(['profile'], { origin: 'us', realm: 'amanthul', name: 'charni' })
      .then(response => {
        console.log(response.data);
      });
    

    Full code example with async/await

    const blizzard = require('blizzard.js').initialize({
      key: process.env.BLIZZARD_CLIENT_ID,
      secret: process.env.BLIZZARD_CLIENT_SECRET,
      origin: 'us',
      locale: 'en_US'
    });
    
    async function example () {
      try {
        await blizzard.getApplicationToken()
          .then(response => {
            blizzard.defaults.token = response.data.access_token
          });
        const item = await blizzard.wow.item({ id: 168185 });
        console.log(item)
      } catch (err) {
        console.error(err);
      }
    }
    
    example();
    

    Battle.net API Key

    Your private Blizzard API Client ID, Secret & token must be passed to .initialize(). Please see the documentation at the Blizzard Developer Portal to obtain your own Blizzard API credentials.

    Show All