npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cthos/gw2-api

v4.0.1

Published

GuildWars 2 API interface

Downloads

50

Readme

GW2-API

⚠️ 4.0.0 breaks out all of the API calls into multiple classes so you can use them independently or through the main export. Type definitions are coming, but are not yet completed.

This is a node module which is designed to facilitate communication with the Guild Wars 2 API. It is fan maintained, and has no official relationship with Arenanet or GuildWars 2 (legal disclaimer at the bottom).

The goal is to provide some convenience methods around getting things out of the API. This includes ways to cache API call results in memory, localStorage, or whatever storage system you desire. This is useful for the big aggregate lists (for example /items).

Instructions

The gw2 package comes with 2 objects exported. gw2 is the actual interface to the API with a default storage mechanism of localStorage. Since this isn't available in all applications, it also provides memStore, which simply caches things in RAM. Storage can also be disabled by calling api.setCache(false).

API Documentation

Static API Documentation Page

Example (for ^3.0.0)

Typescript

import { GW2API, Memstore } from "@cthos/gw2-api";

const api = new GW2API();

// Set storage system to RAM if no access to localStorage
api.setStorage(new Memstore());

// Get daily pve achievement names:
const achievements = await api.getDailyAchievements(true); // the true is default, but this will translate the IDs to their objects directly
const achievementNames = achievements.map((a) => a.name);

// Get all character names associated with an account.
await api.setAPIKey("YOUR-TOKEN-GOES-HERE");

api.getCharacters().then(function (res) {
  for (var i = 0, len = res.length; i < len; i++) {
    // This API call just returns an array of string character names.
    console.log(res[i]);
  }
});

// Get Character Details
api.getCharacters("Zojja").then(function (res) {
  console.log(res);
});

Javascript

Example (for 2.2.2)

var gw2 = require("gw2-api");
var api = new gw2.gw2();

// Set storage system to RAM if no access to localStorage
api.setStorage(new gw2.memStore());

// Get daily pve achievement names:
api
  .getDailyAchievements()
  .then(function (res) {
    if (!res.pve) {
      return;
    }

    var achievementIds = [];

    for (var i = 0, len = res.pve.length; i < len; i++) {
      achievementIds.push(res.pve[i].id);
    }

    return api.getAchievements(achievementIds);
  })
  .then(function (res) {
    for (var i = 0, len = res.length; i < len; i++) {
      console.log(res[i].name);
    }
  });

// Get all character names associated with an account.
api.setAPIKey("YOUR-TOKEN-GOES-HERE");

api.getCharacters().then(function (res) {
  for (var i = 0, len = res.length; i < len; i++) {
    // This API call just returns an array of string character names.
    console.log(res[i]);
  }
});

// Get Character Details
api.getCharacters("Zojja").then(function (res) {
  console.log(res);
});

Gotchas

CORS Errors

Unfortunately, near as I can tell the GW2 API doesn't support responding to CORS OPTIONS requests, so if you want to call this from a browser you can't use the Authorization header method (which is now defaulted to off, and instead using a query parameter instead).

Legal stuff

Use of the Guild Wars 2 API constitutes compliance with the Content Terms of Use and the Website Terms of Use.

Full API documentation is found on the Wiki.

Their copyright notice is:

© 2015 ArenaNet, LLC. All rights reserved. NCSOFT, the interlocking NC logo, ArenaNet, Guild Wars, Guild Wars Factions, Guild Wars Nightfall, Guild Wars: Eye of the North, Guild Wars 2, Heart of Thorns, and all associated logos and designs are trademarks or registered trademarks of NCSOFT Corporation. All other trademarks are the property of their respective owners.