Question

Okay so the basically I'm building an application to connect to xero on the activecollab framework. And I'm testing the xeroapi php script created by David Pitman. And I'm just trying to find out why my browser responds with The connection to the server was reset while the page was loading. (but doesn't generated any liveheaders nor does firebug pick anything up)...

thumb
(source: iforce.co.nz)

Here is a snippet of code, that is being used. (Everything has been setup prior using the XERO Api previewer and openssl.)

    define('XERO_KEY','my-key-here'); //hidden for privacy reasons
    define('XERO_SECRET','my-key-here'); //hidden for privacy reasons
    define('XERO_PUBLIC_KEY_PATH', 'path/to/public.key');
    define('XERO_PRIVATE_KEY_PATH', 'path/to/privatekey.pem');

    $xero = new Xero(XERO_KEY, XERO_SECRET, XERO_PUBLIC_KEY_PATH, XERO_PRIVATE_KEY_PATH, 'xml' );  
    $organisation = $xero->organisation;  

    //echo the results back  
    if ( is_object($organisation) ) {  
    //use this to see the source code if the $format option is "xml"  
    echo htmlentities($organisation->asXML()) . "<hr />";  
    } else {  
    //use this to see the source code if the $format option is "json" or not specified  
    echo json_encode($organisation) . "<hr />";  
    }

And my problem is... that the error_log (php) doesn't display any errors a part from a warning:

2012-07-23 21:59:42 Notice : Undefined index: port (at C:\xampp\htdocs\ac3\activecollab\3.1.10\modules\xero_invoice_manager\lib\xero\xero.class.php on 644 line)

The code on xero.class.php line 644

/**
* parses the url and rebuilds it to be
* scheme://host/path
*/
public function get_normalized_http_url() {
$parts = parse_url($this->http_url);

$port = @$parts['port']; //this line says its undefined
$scheme = $parts['scheme'];
$host = $parts['host'];
$path = @$parts['path'];

$port or $port = ($scheme == 'https') ? '443' : '80';

if (($scheme == 'https' && $port != '443')
    || ($scheme == 'http' && $port != '80')) {
  $host = "$host:$port";
}
return "$scheme://$host$path";
}

From investigating I've found on print_r the result of $parts in a preformatted tag is..

Array
(
    [scheme] => https
    [host] => api.xero.com
    [path] => /api.xro/2.0/Organisation
)

The same information is used on a live server (for the past couple of months). but the xeroapi class is not working on the test server, does anyone have any advice as to why it isn't connecting? I'm running XAMPP Control Panel with apache on port 80 and PHP Version 5.3.8.

Was it helpful?

Solution

I'm not sure about your port issue.

However, the Xero API require an OAuth set-up, which is presumably done for you in the Xero class. Part of the OAuth stuff is setting a callback domain, this requires you register a callback domain with Xero. Xero allows you to use subdomains of the registered domain and I assume that the Xero class uses request information to set the correct domain.

On localhost, that domain is localhost, which is not a subdomain. You can register localhost, or do what I have done (because I don't have access to the Application account), and set a special local subdomain in your hosts file.

So if you use example.com, then a good 'local' domain is local.example.com. Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top