1

I am trying to make a simple CURL call to GetReponse using PHP and I must be doing something wrong. Each time I try to use my clients access token it bombs out. If I hard code my company API key into the place where I've put the xxxxx's it works fine. I'm using their docs, but I can't get it to work, any help? Btw, their docs are HORRIBLE - so bad I can't even begin to fully explain! They're filled with a billion typos... Their Docs

        $url = "https://api.getresponse.com/v3/campaigns";
        $headers = array();
        $headers[] = "X-Auth-Token: api-key xxxxxxxxx";
        $state_ch = curl_init();
        curl_setopt($state_ch, CURLOPT_URL, $url);
        curl_setopt($state_ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($state_ch, CURLOPT_HTTPHEADER, $headers);
        $state_result = curl_exec ($state_ch);
        $state_result = json_decode($state_result);
        $debug = 1;
        print_r($state_result);

I always get the same response:

stdClass Object
(
[httpStatus] => 401
[code] => 1014
[codeDescription] => Problem during authentication process, check headers!
[message] => Unable to authenticate request. Check credentials or authentication method details
[moreInfo] => https://apidocs.getresponse.com/en/v3/errors/1014
[context] => stdClass Object
    (
        [authenticationType] => auth_token
    )

[uuid] => xxxxxxxxxxxxxxxxxxxxxxxxx
)

Again, if I put my company API key in the place of the xxxxxx's (which I have to get inside of their control panel) it works. Access tokens do not.

Solution:

Looks like the header needs to change to this...

$headers[] = "Authorization: Bearer xxxxxxxxxxxxxxx"
LargeTuna
  • 2,694
  • 7
  • 46
  • 92

2 Answers2

0

As I can see:

[httpStatus]401 = unauthorized

Check your API token permission

BusyProgrammer
  • 2,783
  • 5
  • 18
  • 31
  • They say "401 - We cannot find authentication information in your request, and if we cannot determine who you are we cannot fulfill your request. Please add authentication header!" -- I say "I am adding that header." – LargeTuna Mar 07 '17 at 03:50
  • Found it: $headers[] = "Authorization: Bearer xxxxxxxxxxxxxxx" - Glad they are absolutely UNCLEAR about this in the docs. – LargeTuna Mar 07 '17 at 03:55
  • Did u find another doc documents? – Adam Kozlowski Jul 25 '18 at 11:45
0

I'm using next code:

$headers = [];
$headers[] = "X-Auth-Token: api-key MY_API_KEY";        

$ch = curl_init('https://api.getresponse.com/v3/campaigns');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                        
curl_setopt($ch, CURLOPT_TIMEOUT, 10);          
$result = curl_exec($ch);

if($result)
{
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($result, 0, $header_size);
        $body = substr($result, $header_size);
}

curl_close($ch);