PHP code example of gw2treasures / gw2api

1. Go to this page and download the library: Download gw2treasures/gw2api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gw2treasures / gw2api example snippets






// create new api instance
$api = new \GW2Treasures\GW2Api\GW2Api();

// get all worlds
$worlds = $api->worlds()->all();

// get some happy quaggans
$quaggans = $api->quaggans()->many([ 'cheer', 'party' ]);

// get item details in german
$ektoplasmakugel = $api->items()->lang('de')->get(19721);

// search recipes
$recipes = $api->recipes()->search()->input(46746);

// get all character names
$characters = $api->characters('api_key')->ids();

// get 10 recently bought items
$recentlyBought = $api->commerce()->transactions('api_key')->history()->buys()->page(0, 10);

$api->items()->all();
// => returns array with all items

$api->items()->ids();
// => returns array with all item ids

$api->items()->get(1);
// => returns item with id 1

$api->items()->many([1,2,3]);
// => returns items with ids 1, 2 and 3

$api->items()->lang('de')->get(1)
// => returns german item 1

$api->items()->all();
// => returns all items

$api->items()->page(0, 10);
// => returns first page of 10 items

$api->items()->batch(function($items) {
    // $items contains items of current batch.
    // gets called multiple times with different items untill all items have been processed.
});

try {
    $api->items()->get('invalid item id');
} catch(ApiException $exception) {
    $exception->getMessage() === "no such id"
}

try {
    $api->account('INVALID_API_KEY')->get();
} catch(AuthenticationException $exception) {
    $exception->getMessage() === "invalid key"
}

try {
    $api->characters('API_KEY_WITHOUT_CHARACTERS_SCOPE')->get();
} catch(InvalidPermissionsException $exception) {
    $exception->getMessage() === "

try {
    $api->items()->lang('invalid')->get(1);
} catch(InvalidLanguageException $exception) {
    $exception->getMessage() === "Invalid language (expected: invalid; actual: en)"
    $exception->getRequestLanguage() === "invalid"
    $exception->getResponseLanguage() === "en"
}

try {
    $api->items()->page(9001);
} catch(PageOutOfRangeException $exception) {
    $exception->getMessage() === "page out of range. Use page values 0 - 826."
}

try {
    $api->guild()->membersOf('API_KEY', 'GUILD_ID_YOU_ARE_NOT_LEADER_OF');
} catch(GuildLeaderRequiredException $exception) {
    $exception->getMessage() === "access restricted to guild leaders"
}

try {
    $api->guild()->membersOf('API_KEY', 'GUILD_ID_YOU_ARE_NOT_A_MEMBER_OF');
} catch(GuildLeaderRequiredException $exception) {
    $exception->getMessage() === "membership 

$api->account('API_KEY')->get();
// => { id: "account-guid", name: "Lawton.1234", … }

$api->account('API_KEY')->achievements()->get();
// => [ { id: 1, current: 1, max: 1000, done: false }, … ]

$api->account('API_KEY')->bank()->get();
// => [ null, { id: 46774, slot: 1, count: 1 }, … ]

$api->account('API_KEY')->dyes()->get();
// => [ 8, 12, 14, 17, … ]

$api->account('API_KEY')->finishers()->get();
// => [ { id: 1, permanent: true }

$api->account('API_KEY')->inventory()->get();
// => [ null, { id: 12138, count: 250 }, null ]

$api->account('API_KEY')->masteries()->get();
// => [ { id: 4, level: 4 }, … ]

$api->account('API_KEY')->materials()->get();
// => [ { id: 19699, category: 5, count: 250 }, … ]

$api->account('API_KEY')->minis()->get();
// => [ 1, 2, 3, 4, … ]

$api->account('API_KEY')->novelties()->get();
// => [ 1, 2, 3, 4, … ]

$api->account('API_KEY')->recipes()->get();
// => [ 104, 105, 106, 107, … ]

$api->account('API_KEY')->skins()->get();
// => [ 1, 2, 3, 4, … ]

$api->account('API_KEY')->titles()->get();
// => [ 1, 17, 188, … ]

$api->account('API_KEY')->wallet()->get();
// => [ { id: 1, value: 234885 }, … ]

$api->achievements()->get(1);
// => { id: 1, name: "Centaur Slayer", … }

$api->achievements()->categories()->get(50);
// => { id: 50, name: "Twilight Assault", … }

$api->achievements()->daily()->get();
// => { pve: [ { id: 1984, level: { min:1, max: 80 } }, … ], pvp: [ … ], wvw: [ … ] }

$api->achievements()->daily()->tomorrow()->get();
// => { pve: [ { id: 1973, level: { min:1, max: 79 } }, … ], pvp: [ … ], wvw: [ … ] }

$api->achievements()->groups()->get('65B4B678-607E-4D97-B458-076C3E96A810');
// => { id: "65B4B678-607E-4D97-B458-076C3E96A810", name: "Heart of Thorns", … }

$api->backstory()->answers()->get('7-54');
// => { id: "7-54", title: "Dignity", question: 7, … }

$api->backstory()->questions()->get('7');
// => { id: 7, title: "My Personality", answers: [ "7-53", "7-54", "7-55" ], … }

$api->build()->get();
// => 50430

$api->characters('API_KEY')->get('Character Name');
// => { name: "Hello", race: "Human", … }

$api->characters('API_KEY')->backstoryOf('Character Name')->get();
// => [ "26-122", "27-125", … ]

$api->characters('API_KEY')->coreOf('Character Name')->get();
// => { name: "Test Char", race: "Norn", gender: "Female", … }

$api->characters('API_KEY')->craftingOf('Character Name')->get();
// => [ { discipline: "Tailor", rating: 400, active: true }, … ]

$api->characters('API_KEY')->equipmentOf('Character Name')->get();
// => [ { id: 6472, slot: "Coat" }, … ]

$api->characters('API_KEY')->heropointsOf('Character Name')->get();
// => [ "0-3", "0-4", "0-5", "0-6", "0-8", … ]

$api->characters('API_KEY')->inventoryOf('Character Name')->get();
// => [ { id: 8941, size: 4 inventory: [ null, { id: 32134, count: 1 }, … ] }, … ]

$api->characters('API_KEY')->recipesOf('Character Name')->get();
// => [ 7, 8, 9, 10, 11, … ]

$api->characters('API_KEY')->skillsOf('Character Name')->get();
// => { pve: { heal: 5503, utilities: [ 5641, 5734, 5502 ], elite: 5666 }, … }

$api->characters('API_KEY')->specializationsOf('Character Name')->get();
// => { pve: [ { id: 41, traits: [232, 214, 226] }, … ], … }

$api->characters('API_KEY')->trainingOf('Character Name')->get();
// => [ { id: 111, spent: 24, done: true }, … ]

$api->colors()->lang('de')->all();
// => [ { id: 1, name: "Farbentferner", base_rgb: [128,26,26], … }, … ]

$api->commerce()->exchange()->gems(50);
// => { coins_per_gem: 1211, quantity: 60579 }

$api->commerce()->listings()->get(24);
// => { id: 24, buys: [ { listings: 1, unit_price: 186, quantity: 250 }, … ] }

$api->commerce()->prices()->get(24);
// => { id: 24, buys: { quantity: 20854, unit_price: 186 }, sells: { quantity: 9787, unit_price: 340 } }

$api->commerce()->transactions('API_KEY')->current()->sells()->all();
// => [ { id: 1999, item_id: 19699, price: 1004, quantity: 20, created: "2014-12-15T14:43:36+00:00" }, … ]

$api->continents()->get(1);
// => { name: "Tyria", … }

$api->currencies()->get(1);
// => { id: 1, name: "Coin", … }

$api->continents()->floorsOf(1)->get(0);
// => { texture_dims: [ 32768, 32768 ], … }

$api->emblem()->foregrounds()->get(1);
// => { id: 1, layers: [ "59641.png", "59643.png", "59645.png" ] }

$api->files()->ids();
// => [ "map_complete", "map_dungeon", … ]

$api->finishers()->get();
// => { id:1, name: "Rabbit Rank Finisher", … }

$api->guild()->detailsOf('GUILD_ID');
// => { id: "GUILD_ID", name: "Test Guild", tag: "API", … }

$api->guild()->detailsOf('GUILD_ID', 'API_KEY');
// => { level: 42, motd: "gw2treasures.com\n", id: "GUILD_ID", name: "Test Guild", tag: "API", … }

$api->guild()->logOf('API_KEY', 'GUILD_ID');
// => [ { id: 1190, time: "…", type: "treasury", user: "Lawton Campbell.9413", … }, … ]

$api->guild()->membersOf('API_KEY', 'GUILD_ID');
// => [ { name: "darthmaim.6017", rank: "Leader", joined: "2015-12-16T02:50:26.000Z" } ]

$api->guild()->ranksOf('API_KEY', 'GUILD_ID');
// => [ { id: "Leader", order: 1, permissions: [ "Admin", … ], icon: "…" }, … ]

$api->guild()->stashOf('API_KEY', 'GUILD_ID')->get();
// => [ { upgrade_id: 1, size: 100, coins: 1002, note: "stash test", inventory: [] } ]

$api->guild()->teamsOf('API_KEY', 'GUILD_ID')->get();
// => [ { id: 1, members: [], name: "ez game" } ]

$api->guild()->treasuryOf('API_KEY', 'GUILD_ID')->get();
// => [ { id: 123, count: 100, needed_by: [] } ]

$api->guild()->upgradesOf('API_KEY', 'GUILD_ID')->get();
// => [ 38, 43, 44, 51, 55, … ]

$api->guild()->permissions()->ids();
// => [ "ClaimableEditOptions", "EditBGM", "ActivatePlaceables", … ]

$api->guild()->upgrades()->get(38);
// => { id: 38, name: "Guild Armorer 1", … }

$api->home()->cats()->get('1');
// => { id: 1, hint: "chicken", … }

$api->mounts()->skins()->ids();
// => [ "advanced_cloth_rack", "advanced_leather_rack", … ]

$api->items()->ids();
// => [ 1, 2, 6, 11, 24, … ]

$api->itemstats()->get(137);
// => { id: 137, name: "Mighty", attributes: { Power: 0.35 } }

$api->legends()->get('Legend1');
// => { id: "Legend1", swap: 28229, heal: 27220, … }

$api->maps()->get(15);
// => { id: 15, name: "Queensdale", … }

$api->masteries()->get(15);
// => { id: 1, name: "Exalted Lore", … }

$api->materials()->lang('es')->all();
// => [ { id:5, name: "Materiales de cocina", items: [ 12134, … ] }, … ]

$api->minis()->get(1);
// => { id: 1, name: "Miniature Rytlock", … }

$api->mounts()->types()->get('raptor');
// => { id: "raptor", name: "Raptor", … }

$api->mounts()->skins()->get(1);
// => { id: 1, mount: "raptor", … }

$api->novelties()->get(1);
// => { id: 1, name: "Embellished Kite", … }

$api->outfits()->get(1);
// => { id: 1, name: "Cook's Outfit", … }

$api->pets()->get(1);
// => { id: 1, name: "Juvenile Jungle Stalker", … }

$api->professions()->get('Warrior');
// => { id: "Warrior", name: "Warrior", … }

$api->pvp()->amulets()->get(4);
// => { id: 4, name: "Assassin Amulet", … }

$api->pvp('API_KEY')->games()->get('A9F9FD97-F114-4F97-B2CA-5E814DF0340E');
// => { id: "A9F9FD97-F114-4F97-B2CA-5E814DF0340E", map_id: 795, … }

$api->pvp()->seasons()->get('44B85826-B5ED-4890-8C77-82DDF9F2CF2B');
// => { id: "44B85826-B5ED-4890-8C77-82DDF9F2CF2B", name: "PvP League Season One", … }

$api->pvp()->standings('API-KEY')->get();
// => [{ current: { total_points: 101, … }, best: { total_points: 200, … }, … }]

$api->pvp('API_KEY')->stats()->get();
// => { pvp_rank: 57, aggregate: { wins: 343, … }, … }

$api->quaggans()->many(['cheer', 'party']);
// => [ { id: "cheer", url: "cheer.jpg" }, { id: "party", url: "party.jpg" } ]

$api->recipes()->ids();
// => [ 1, 2, 3, 4, 5, … ]

$api->recipes()->search()->input(43775);
// => [ 7259, 7260, 7261, 7262, … ]

$api->skills()->get(1);
// => { name: "Bandage", facts: [ { text: "Recharge", type: "Recharge", icon: "…", value: 5 } ], … }

$api->skins()->get(1);
// => { name: "Chainmail Leggings", type: "Armor", … }

$api->specializations()->get(1);
// => { id: 1, name: "Dueling", profession: "Mesmer", … }

$api->titles()->get(1);
// => { id: 1, name: "Traveler", achievement: 111 }

$api->stories()->get(1);
// => { id: 1, season: "215AAA0F-CDAC-4F93-86DA-C155A99B5784", name: "My Story", … }

$api->stories()->seasons()->get('215AAA0F-CDAC-4F93-86DA-C155A99B5784');
// => { id: "215AAA0F-CDAC-4F93-86DA-C155A99B5784", name: "My Story", … }

$api->titles()->get(1);
// => { id: 1, name: "Traveler", achievement: 111 }

$api->tokeninfo('API_KEY')->get();
// => { id: "API_KEY", name: "key name", permissions: [ "account", … ] }

$api->traits()->get(214);
// => { id: 214, tier:2, name: "Aeromancer's Training", … }

$api->worlds()->all();
// => [ { id: 1001, name: "Anvil Rock" }, … ]
php
$api->wvw()->abilities()->get(2);
// => { id: 2, name: "Guard Killer", … }
php
$api->wvw()->matches()->get('2-6');

// => { id: "2-6", "scores": { red: 169331, blue: 246780, green: 216241 }, … }