0

I'm trying to work off the Harvest php API example from the GitHub page.

Here is the code, but there is no output no matter what I try to do. If I use the Chrome Postman app I can retrieve data. I'm not sure what I'm doing wrong. Confidential information was removed. Any help is much appreciated.

<?php

$url = "https://company.harvestapp.com/?daily=";

$temp = getURL($url);
echo $temp;

function getURL($url) { 

    $credentials = "<email>:<password>";
    $headers = array(
        "Content-Type: application/xml",
        "Accept: application/xml",
        "Authorization-Basic: " . base64_encode($credentials)
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_USERAGENT, "test app site");

    $data = curl_exec($ch);
    curl_close($ch);

    if ($data !=false){
        return $data;
        }
    else
        return "no data";

}
?>

This is the error I get from the curl_error function:

HTTP/1.1 401 Unauthorized Server: nginx Date: Fri, 09 May 2014 22:59:27 GMT Content-Type: application/xml; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Status: 401 Unauthorized Cache-Control: private, no-store, no-cache, max-age=0, must-revalidate X-Frame-Options: SAMEORIGIN X-Served-From: https://.harvestapp.com/ X-UA-Compatible: IE=Edge,chrome=1 Set-Cookie: _harvest_sess=; domain=.harvestapp.com; path=/; secure; HttpOnly X-Request-Id: e9d6eb74-5c73-430e-9854-ebf6f1c527c8 X-Runtime: 0.019223 You must be authenticated with Harvest to complete this request.

Sammitch
  • 30,782
  • 7
  • 50
  • 77
mgalal
  • 427
  • 12
  • 24
  • can you turn on php.ini display_errors = on ? – Pogrindis May 09 '14 at 21:23
  • I added the error message I received. I'm testing this using XAMPP on my laptop. I wasn't sure if it would matter if the script was on a web-server instead. However, I'll try that too. – mgalal May 09 '14 at 23:03
  • `401 Unauthorized` aka your authentication either failed or never happened. – Sammitch May 09 '14 at 23:16
  • I tried the same authentication using the Postman app on Chrome and it worked. Do you have an idea why it would fail with this script? – mgalal May 09 '14 at 23:19
  • @mgalal Hi. I am facing the same Issue right now. Did you find a workaround to it? – user3402248 Apr 14 '16 at 14:41

0 Answers0