Skip to content

Examples

Copy-paste oriented samples. Full files live in packages/api/examples/.

From the monorepo root:

bash
bun run packages/api/examples/basic.ts

Minimal client

ts
import { WynnClient } from "@wynnjs/api";

const client = new WynnClient();
const { data, rateLimit } = await client.classes.list();

console.log(
  Object.values(data).map((entry) => entry.name),
  rateLimit?.remaining,
);

API token + whoami

ts
import { WynnClient } from "@wynnjs/api";

const client = new WynnClient({
  auth: { type: "token", token: process.env.WYNN_API_TOKEN! },
});

const { data: identities } = await client.player.whoAmI();

for (const identity of Object.values(identities)) {
  console.log(identity.username, identity.online);
}

Player profile + characters

ts
import { WynnClient } from "@wynnjs/api";

const client = new WynnClient();
const username = "YourUsername";

const { data: profile } = await client.player.getPlayer(username, {
  fullResult: true,
});

console.log(profile.username, profile.online, profile.guild?.name);

const { data: characters } = await client.player.listCharacters(username);

for (const [uuid, character] of Object.entries(characters)) {
  console.log(uuid, character.type, character.nickname);
}
ts
import { WynnClient } from "@wynnjs/api";

const client = new WynnClient();

const { data: results } = await client.item.searchItems(
  { query: "wand", tier: "legendary" },
  { page: 0 },
);

console.log(results.controller.count, results.results.length);

const { data: quick } = await client.item.quickSearchItems("helmet");
console.log(quick.map((item) => item.displayName));

Typed errors

ts
import { WynnApiError, WynnClient } from "@wynnjs/api";

const client = new WynnClient();

try {
  await client.player.getPlayer("DefinitelyNotARealPlayer_12345");
} catch (error) {
  if (error instanceof WynnApiError.NotFound) {
    console.error("missing:", error.detail);
  } else if (error instanceof WynnApiError.MultipleObjectsReturned) {
    console.error("pick one:", error.objects);
  } else if (error instanceof WynnApiError) {
    console.error(error.error, error.status, error.detail);
  } else {
    throw error;
  }
}

More in the repo

FileCovers
oauth.tsOAuth me + exchange sketch
guild-and-search.tsSearch, guild, leaderboard types
ability.tsTree, map, aspects
map.tsMarkers, events, camps
news.tsArticles + videos

Cookbooks

RecipePage
Walk every pagePagination
MultipleObjectsReturnedAmbiguous matches
OAuth code → token → meOAuth
Session cookiesSession auth
Budget + backoffRate limits
Recipe full_resultRecipe fullResult
assetUrl / CDN pathsCDN assets

Use fictional usernames and UUIDs. Do not commit real player data, tokens, or session cookies.

Unofficial TypeScript tooling for the Wynncraft API