2

I am trying to access the ClickBank API from my Delphi project, to check if a customer has a valid subscription.

I found the API Documentation here, but there are no Delphi examples. So I am trying to create my own little example, however I just cant figure it out with Indy's TIdHTTP.

Could anyone point me in the right direction, perhaps set up a minimal example?

P.S: I tried looking at the C# sample, however I cant port it to Delphi.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Jeff
  • 12,085
  • 12
  • 82
  • 152
  • It seems the Clickbank api is "just" another REST api and is capable of returning JSON. Therefore, check out the SuperObject library: http://www.progdigy.com/?page_id=6 It is a fast JSON parser and comes with examples on how to use REST services like Google search and Google search suggest. – Marjan Venema May 20 '11 at 14:41
  • Would the person who downvoted my question please justify? If I dont get a reason, I dont know what to improve. :) – Jeff May 20 '11 at 16:51
  • @Marjan - Checked out the demos, however I cant really figure out how I would do this with the Clickbank API. Would you mind creating an Answer with samplecode? That would be splendid! :) – Jeff May 20 '11 at 17:01
  • Sorry no, other things to do. – Marjan Venema May 20 '11 at 17:53
  • @Marjan - Dont worry, I understand. :) – Jeff May 20 '11 at 18:09

1 Answers1

4

ClickBank sample C# is found here https://sandbox.clickbank.com/api_12_examples/api_example.csharp

HttpWebRequest request = (HttpWebRequest)
    WebRequest.Create("https://api.clickbank.com/rest/1.2/orders/list");
request.Accept = "application/xml";
request.Headers.Add(HttpRequestHeader.Authorization,
        "<< DEVELOPER KEY >>:<< API KEY >>");
request.Method = "GET";

HttpWebResponse response = (HttpWebResponse) request.GetResponse();

The PHP version is https://sandbox.clickbank.com/api_12_examples/api_example.php

You'll see that they aren't doing much setup here... just setting two headers and performing a GET.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/orders/list");
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Accept: application/xml",
        "Authorization: << DEVELOPER KEY >>:<< API KEY >>"));
$result = curl_exec($ch);
curl_close($ch);

In Delphi - a quick demo is to drop a TIdHTTP1 client on a form, along with a Button and a Memo. Then on an onclick of the button (where xxx= your developer key and yyy= your api key) do the same - set two headers and perform a GET:

IdHTTP1.Request.Accept := 'application/xml';
IdHTTP1.Request.CustomHeaders.Add('Authorization: xxx:yyy');
Memo1.Text := IdHTTP1.Get('https://api.clickbank.com/rest/1.2/orders/list');
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Darian Miller
  • 7,808
  • 3
  • 43
  • 62
  • 1
    Just noticed that it was HTTPS - you'll also need to set the OpenSSL IOHandler to handle SSL. Perhaps this is your problem - you don't have the required SSL libraries. See http://stackoverflow.com/questions/1874677/indy-10-1-5-which-ssl-dlls-work – Darian Miller May 20 '11 at 18:15
  • Hmm, its not a Delphi Library? Then how do I use it with TIdHTTP? Do I need to include the OpenSSL.exe + dlls with my application? – Jeff May 20 '11 at 19:05
  • @Jeff: Read the [Indy docs](http://www.indyproject.org/Sockets/Docs/index.EN.aspx) - there's an entire page dedicated to using SSL with Indy, IIRC. But how to configure Indy SSL would be an entirely different question than this one anyway. – Ken White May 20 '11 at 19:44
  • I got it working - appears the API key was needed **aswell** (even though I could have sworn I read that it was not required). – Jeff May 20 '11 at 19:50