Php Gist for the new Api with oauth

API Discussion
In case you are needing for a Php library for the new Api:

You can just require this two libraries into your project: and

And here is an example how you can use both libraries:


namespace Your\Namespace;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use kamermans\OAuth2\GrantType\ClientCredentials;
use kamermans\OAuth2\OAuth2Middleware;

// This client you use to get your token
$tokenClient = new Client([
'base_uri' => '',

$tokenConfig = [
"client_id" => 'your client_id',
"client_secret" => 'your client_secret',

$grant_type = new ClientCredentials($tokenClient, $tokenConfig);
$oauth = new OAuth2Middleware($grant_type);
$stack = HandlerStack::create();


// This client you use to get your wow data, for example a char data
$client = new Client([
'handler' => $stack,
'auth' => 'oauth',

//Build your url, for example to get your char data
$url = '' . $realm . '/' . $name;

$response = $client->get($url);

// ...and here ist your json response

Just then forget about CURL BLA FOO and happy coding
Hey, any idea what encoding the json response comes in?
I only file_get_contents (even more simple than Curl lol) to get it, then slice the !@#$ through consecutive explodes... No problem isolating sellers and item values from the AH API, but for some reason when I compare "fëëdyoureggo" to "fëëdyoureggo" or even "dikku" to "dikku", I get false...

Here's my BIG BIG BIG 30line boy :
// array of banking toons to servers
$sellers_to_realms = array(
"dragonblight" => "Fëëdyoureggo"

// gets data stringed array from API...
$header_response = file_get_contents("{$_REQUEST["realm"]}?locale=en_US&apikey=YoUrMoM");
$url1 = explode("url".chr(34).":".chr(34),$header_response);
$url2 = explode(chr(34),$url1[1]);
$url = $url2[0];
$data = file_get_contents($url);
$auctions = explode("{".chr(34)."auc".chr(34).":",$data);

// boucle de calcul...
$total_copper = 0;
foreach ($auctions as $auction_string) {
$seller1 = explode("owner".chr(34).":".chr(34),$auction_string);
$seller2 = explode(chr(34),$seller1[1]);
$seller = $seller2[0];
$ss = strtolower($seller);
if ($ss == "dikku") {
$value1 = explode("buyout".chr(34).":",$auction_string);
$value2 = explode(",",$value1[1]);
$value = $value2[0];
$total_copper = $total_copper + $value;
echo "Your auctions on {$_REQUEST["realm"]} are worth {$total_copper} copper pieces.";

Weirdly enough the $seller string is converted to lower case, which should default its type as string no matter in what type it came to start with...

Note that the "if ($ss == "dikku")" is only temporary code made to test the script, targeting it to dikku's auctions while the actual statement should be
"if ($seller == $sellers_to_realms[$_REQUEST["realm"]])".

If I make the script add up all auction values for auctions whose sellers' names are 12 character long, it works and outputs a value so everything is working fine but that damn string comparison...

Thanks for your help
I don't really know what are you trying to achieved with the script you posted.
Exploding json responses to get any information out of it, is the wrong way.

Anyway you can make a post explaining WHAT you want to achieved and WHAT is your problem, that anyone can give you the help you need or point you in the right direction.

Anyway, if you want to get auctions data with file_get_contents you can do it this way: $auctionApi = "{$_REQUEST["realm"]}?locale=en_US&apikey=YoUrMoM";

$auctionApiResponse = json_decode(file_get_contents($auctionApi));

// you should read what current do:
$firstResponseItem = current($auctionApiResponse->files);

// get the url from your returned array item
$auctionsUrl = $firstResponseItem->url;

// get your auction data as array
$data = json_decode(file_get_contents($auctionsUrl), true);

$total_copper = 0;

// ...and iterate in the array to get what you need
foreach($data['auctions'] as $auction) {
// do whatever here to get what you want
$seller = $auction['owner'];

if ($seller === 'Dikku') {
$total_copper += $auction['buyout'];

echo "Your auctions on {$_REQUEST["realm"]} are worth {$total_copper} copper

I hope this could help you, if this is what you need.

Join the Conversation

Return to Forum