Delphi Component for Blizzard API

Currently, I manually input relevant in-game information such as Paragon, Greater Rift, Gold, Damage, etc into an Excel sheet that I use for keeping track of my daily progress.

I would, I believe, be far easier and efficient if I could write an app in Delphi that can access all the relevant data for any particular hero, and can then export said information into Excel.

Processing the JSON returned by API calls isn’t an issue. However, I am unable to locate any components or libraries for RAD Studio Delphi that can handle the OAuth requirements.

Does anyone have any recommendations for me?

I’m a former Delphi developer, I have used it for many years, but unfortunately it is not as popular anymore due to its lack of features compared to other languages, so I doubt you’ll be able to find any good library for this specific API.

I assume you are talking about a desktop application right ? If you only need to interact with data exposed by the client_credentials flow you can easily create your own methods for generating the token using the good old Indy library. A simple post request can handle this flow.

However if you need to use the authorization_code flow (required only for account information like list of characters) it is far more complicated as you’ll have to implement a custom URL protocol for receiving the auth code back from a browser (same as those links that open up apps), I explain this in more details here.

– Edit –
For the client_credentials flow you can also use this proxy to fetch everything with simple get requests instead of having to map all endpoint namespaces and urls in Delphi.

Yes, it is a desktop application of which I speak.

My intention with it is indeed to retrieve a list of my heroes, and then to further find as much in-game information about each of them as possible.

I wish to do this to avoid the inefficiency of writing it down manually and then re-typing into Excel.

The Delphi component/s I’m looking for is to handle the required OAuth part of the Blizzard API…

EDIT 2020-11-09T05:15:00Z:

Is it possible for me to compile a JSON file similar to the following (as an example):

  "Client ID": "-------------------",
  "Client Secret": "-------------------",

which can then in turn be POSTED using the Delphi component “TNetHTTPClient” so as to return an appropriate access token?

It would appear then as if I could use the JSON presented by the API to gather most the information I require about my heroes when using

Can it be done?

Are you interested only in D3 heroes ? Sorry I was considering World of Warcraft. :frowning_face:

Good news: yes, you can get all the data you want with the client credentials flow. If you are new to the API and OAuth this topic might be useful.

That is great news, Schiller, thank you.

Now the question is how to provide a ClientID and ClientSecret in my App order to gain a new OAuthToken? Once I have the OAuthToken, parsing the provide JSON data is easy enough…

Using “Try It” in
is easy enough, but it doesn’t show how to POST the ID and Secret myself via my app in order to retrieve the OAuthToken need to go any further…

My apologies if I sound like a noob. Other than actually using it, the internal workings and intricacies of the Web isn’t exactly my forte… :confounded:

Try using this post as a guideline. But it is not really hard, just a POST request using the client ID and secret as basic authorization plus a x-url-encoded form data body with just one field.

The function below was written from memory and a few StackOverflow searches. On success the result should be the whole JSON string returned by the token endpoint. I don’t have Delphi anymore so I can’t test it, but it shouldn’t look much different than this:

function CreateAccessToken(const ClientID, ClientSecret: string): string;
  HTTP: TIdHttp;
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  FormData: TIdMultipartFormDataStream;
  Response: TStringStream;
  HTTP := TIdHttp.Create(nil);
  FormData := TIdMultipartFormDataStream.Create;
  Response := TStringStream.Create('');
  SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
      // SSL support
      SSLHandler.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];
      HTTP.IOHandler := SSLHandler;

      // Authorization header
      HTTP.Request.BasicAuthentication := True;
      HTTP.Request.UserName := ClientID;
      HTTP.Request.Password := ClientSecret;

      // Body payload
      FormData.AddFormField('grant_type', 'client_credentials');

      // Excecute the request
      HTTP.Post('', FormData, Response);

      Result := Response.DataString;
      on E:Exception do
        // Handle exceptions or

I’m a little closer than I was this morning, thanks. But the code keeps giving me an error “Error connecting with SSL. EOF was observed that violates the protocol”.

I have NO idea what that’s about…

Thanks for trying, Schiller. For now I’ll manually copy-and-paste an access token generated the first time I use “Try It” at:

At least that way I can get to the meat of my app and worry about the authentication later… :thinking:

You need to connect an SSL I/O handler to the HTTP client. I don’t remember exactly the name of those components. I only remember there is an IOHandler property and you must pass a pointer to a SSL handler component. You’ll need this for all requests.

I edited the code sample on my previous post, try that now. Sorry but this is as far as I will go on this topic. If you have any question about the API feel free to ask, as for the Delphi/HTTP part you need to visit other forums/resources. You could also ask around in the community discord server to see if anyone there have a working Delphi code they can share.

Thanks, I’ve registered on Discord. Maybe someone there can help.

P.S. Still no-go on the edited code, sorry… :expressionless: