i need to get digital products from click bank, so am using their API to get products, unfortunately given example code given by them are not working, am using CURL to do this ,
code is below :
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.clickbank.com/rest/1.3/products/list");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-KEY:API-KEY"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
?>
but i got the below error
HTTP/1.1 400 Bad Request Date: Thu, 21 Feb 2013 05:20:47 GMT Server: Apache/2.2.23 (FreeBSD) mod_jk/1.2.37 mod_ssl/2.2.23 OpenSSL/0.9.8x Vary: Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/plain The API call (/api/rest/1.3/products/list) requires parameters which are missing : [site]1
have any one got this error before ?
It's expecting a parameter called site. Please see the docs here:
https://api.clickbank.com/rest/1.3/products
Try This:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.clickbank.com/rest/1.3/products/list?site=<your unique affiliate id>");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-KEY:API-KEY"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
?>
Related
I am making a request with CURL using PHP
but I am receiving invalid response format in $result variable.
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$param=json_encode($params);
$post_string = '{"method": "'.$method.'", "params":'.$param.' , "id": "0"}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result='';
$result = curl_exec($ch);
echo $result;
and Result is as following
HTTP/1.1 200 OK Content-Type: application/json Date: Fri, 21 Feb 2020 07:11:50 GMT Content-Length: 36 {"result":[],"error":null,"id":"0"}
but expected is
{"result":[],"error":null,"id":"0"}
I have tried to fetch it with json_decode but it is not working.
Any Suggestion>
Thanks in advance.
You explicitly asked for the headers to be included there.
https://www.php.net/manual/en/function.curl-setopt.php:
CURLOPT_HEADER - TRUE to include the header in the output.
I recently started learning curl to access YouTube API through PHP but for some reason the curl response is empty. At first the response gives me a 301 error so i used FOLLOW LOCATION to follow redirects but now my request doesn't even return headers.
Here's my CURL:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://youtube.com/oembed');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array('url' => 'https://www.youtube.com/watch?v=oorK4RPgZ8Q', 'format' => 'json')
));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
curl_close($ch);
This code worked fine before and still works for the SoundCloud API. Could it be possible that they blocked my requests?
EDIT: Here's the response i get when i remove FOLLOW LOCATION
HTTP/1.1 301 Moved Permanently
Content-Length: 0
Location: https://youtube.com/oembed
Date: Fri, 02 Feb 2018 10:17:41 GMT
Content-Type: text/html
Server: YouTube Frontend Proxy
X-XSS-Protection: 1; mode=block
changed the url and switched 'curl_exec' with 'curl_close':
$ch = curl_init();
$url = 'http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=oorK4RPgZ8Q&format=json';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/*
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array('url' => 'https://www.youtube.com/watch?v=oorK4RPgZ8Q', 'format' => 'json')
));
*/
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
curl_close($ch);
Edit:
as mentioned by creyD and Sewer in the original code the line
curl_setopt($ch, CURLOPT_URL, 'http://youtube.com/oembed');
should be
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com/oembed');
(note the added 'www')
error_reporting(E_ALL);
ini_set("display_errors", 1);
$ch = curl_init();
//$qry_str='?&type=RFND&comment="API refund check"&reason=ticket.type.cancel.7&refundType=FULL';
// curl_setopt($ch, CURLOPT_URL, 'https://api.clickbank.com/rest/1.3/tickets/N5GNE72J/'.$qry_str);
//https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL
//curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E");
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/tickets/RRBKQV4E/?type=RFND&comment=&reason=ticket.type.cancel.7&refundType=FULL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '180');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml","Authorization:DEV-B4VTK7HDKAPDR9842SODK8GI49KAHTHL:API-59RD4F7BORDB7SELOII28DV0EMLIB3IT"));
$result = curl_exec($ch);
$errorCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlInfo = curl_getinfo($ch);
$curlError = curl_error($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
When above code is run I am getting below error :
HTTP/1.1 404 Not Found
Date: Thu, 14 Aug 2014 08:14:19 GMT
Server: Apache/2.2.27 (FreeBSD) mod_jk/1.2.40 mod_ssl/2.2.27 OpenSSL/0.9.8y
Content-Length: 363
Vary: Accept-Encoding
Content-Type: text/html
Please someone help, I am struggling with this for last 1 week but no success.
After a long struggle found the solution. Use below code it worked for me.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://api.clickbank.com/rest/1.3/tickets/627JE7CZ/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/**
* ClickBank doesn't allow POST parameters to be sent in; however, for the CURL POST to work correctly, the
* CURL_POSTFIELDS option must be set, so we'll just set it to empty and put all our request parameters on the URL
*/
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/xml",
"Authorization:DEV-enter your dev key here:API-enter your clerk key here"
));
$result = curl_exec($ch);
curl_close($ch);
?>
This is my sample code for click bank API unfortunately this script do not work
Here is the sample code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/products/list");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: DEV:CLERK"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
If run this code following error has occur
HTTP/1.1 400 Bad Request Date: Sat, 23 Feb 2013 05:24:10 GMT Server: Apache/2.2.23 (FreeBSD) mod_jk/1.2.37 mod_ssl/2.2.23 OpenSSL/0.9.8x Vary: Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/plain The API call (/api/rest/1.3/products/list) requires parameters which are missing : [site]1
https://api.clickbank.com/rest/1.3/products
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/debug");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: DEV:CLERK"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
The required "site" parameter should be the Clickbank ID (also known as vendor).
I am trying to use Sandbox Api of clickBank which accepts a post request.
But somehow it doesnot work.
I am calling clickBank's Prepare Api (https://sandbox.clickbank.com/rest/1.2/sandbox/prepare) using a POST method.
But it giving me this error
HTTP/1.1 405 Method Not Allowed Date: Wed, 07 Nov 2012 12:08:32 GMT Server: Apache/2.2.22 (FreeBSD) mod_jk/1.2.32 mod_ssl/2.2.22 OpenSSL/0.9.8q Allow: POST,OPTIONS Content-Length: 1034 Content-Type: text/html;charset=utf-8 1
Here is my code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://sandbox.clickbank.com/rest/1.2/sandbox/prepare");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:". $dev_key .":" .$api_key ));
$result = curl_exec($ch);
curl_close($ch);
print $result;
I tried everything but it doesnot seem to work.
Any help would be highly appreciated.
Thanks in Advance.
Try this :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sandbox.clickbank.com/rest/1.3/sandbox/prepare");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept:application/json", "Authorization: >>>Your Clickbank Developer API Key from ClickBan->Settings->My Account<<<"));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$return = curl_exec($ch);
curl_close($ch);
Try adding this before your curl_exec():
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
It worked for me, I hope it will work for you too.