Help please: error getting oauth token this week

API Discussion
In updating mounts from the Armory, I've been getting a "502: Bad Gateway" error for the last few days (at least). As far as I can tell it occurs when I request an access token. The code for which is pretty much:


function file_get_contents_curl($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

$data = curl_exec($ch);
curl_close($ch);

return $data;
}

...

$json_data = file_get_contents_curl("https://us.battle.net/oauth/token?grant_type=client_credentials&client_id=<MyClientID>&client_secret=<MyClientSecret>");



Has something changed? Everything was fine a week or so ago, and I can't find any changes specific to this process, just a bunch of new character profile APIs that don't seem relevant to this situation.

Thanks for any help!
The only thing I noticed is that you are using only queryString params to get the access token.

I use a post request instead and everything is working fine, perhaps you could change your code.

The use of post requests is explicit advised here:
https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow
"To request access tokens, an application must make a POST request..."

Here is an example on how to obtain the token:
https://gitlab.com/snippets/1850224
Look for the function createAccessToken
Thanks! Mine just followed Erorus's example page, and was working up to this week. I've tried your approach and got the same error, but I may be doing something else wrong. I'll keep testing.
Bad gateway is not really easy to track.

Can you try your code from a different network to see what happens ? It might be something else blocking the request.
Try eu.battle.net, but with everything else the same. They both use the same account pool, but eu is a different server.
Greetings all,

If you were experiencing issues related to obtaining access tokens using the Code Authorization, or Client Credential flows, the issue should now be resolved as we have addressed an issue which was resulting in unexpected 500 level status code errors for some consumers.

Please do let us know if you continue to experience issues with obtaining access tokens which result in a 500 level status code.
It's working! Thanks very much :)

Join the Conversation

Return to Forum