Clickbank API code not working (It's in PHP)

Discussion in 'PHP' started by ariachik, Nov 11, 2011.

  1. #1
    Hi guys,
    I'm trying cancel a clickbank order using API, but no success, i'm using following code,
    ----------------
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/tickets/R6SDFE9L?type=cncl&reason=ticket.type.cancel.7");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: DEV-removed:API-removed"));
    $result = curl_exec($ch);
    curl_close($ch);


    print $result;
    -------------------

    If any one did it before please give me a hand, Thank you
     
    ariachik, Nov 11, 2011 IP
  2. Narendra Padala

    Narendra Padala Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    The problem was two prong.
    1. I am running PHP 5.2.4 which has a bug accepting custom headers. I found this code, which worked perfectly.

      if(version_compare(PHP_VERSION, '5.3.0') == -1){ ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" . $options['header']); }

    2. Curl would not work. Period. I tried everything. I really have no idea why.
    Here is the final code I ended up with, which works perfectly.

    This interfaces with the Clickbank API via POST. I hope this helps a lot of people.


    <?php
    $options = array('http'=>array('method'=>"POST",'header'=>"Accept: application/xml\r\n"."Authorization: DEV-key-here:API-key-here\r\n"));

    if(version_compare(PHP_VERSION,'5.3.0')==-1){ ini_set('user_agent','PHP-SOAP/'. PHP_VERSION ."\r\n". $options['header']);}

    $context = stream_context_create($options);

    $xml = file_get_contents('https://api.clickbank.com/rest/1.2/tickets/VZR9RYE3?reason=ticket.type.cancel.7&type=cncl',false,$context);

    ?>
     
    Narendra Padala, Jun 18, 2014 IP