youngguns-nl / moneybird_php_api

A PHP Library for the MoneyBird API
http://www.moneybird.nl
MIT License
37 stars 14 forks source link

No output given #74

Open adriaansnoeren opened 9 years ago

adriaansnoeren commented 9 years ago

Just started with the API to provide clients with detailed invoice information. I use the following code:

<?php

require('Moneybird/ApiConnector.php');
spl_autoload_register('Moneybird\ApiConnector::autoload');

$config = array(
    'clientname' => 'clientname', // see Moneybird URL: yourclientname.moneybird.nl
    'emailaddress' => 'emailaddress', // You set this when creating the account
    'password' => 'password', // The password you set in Moneybird when you confirmed the e-mail address
);

// Create a Transport
$transport = new Moneybird\HttpClient();
$transport->setAuth(
    $config['emailaddress'],
    $config['password']
);

$connector = new Moneybird\ApiConnector(
    $config['clientname'],
    $transport, 
    new Moneybird\XmlMapper() // create a mapper
);

$errors = $connector->getErrors();
foreach ($errors as $error) {
    echo $error->attribute . ': ' . $error->message . '<br />';
}

$contactService = $connector->getService('Contact');
$invoiceService = $connector->getService('Invoice');

$contacts = $contactService->getAll();
foreach ($contacts as $contact) {
    echo $contact->name . '<br />';
}

echo 'Requests left: ' . $connector->requestsLeft();

?>

Connecting seems to work. I get the requests left on screen when I remove:

$contacts = $contactService->getAll();
foreach ($contacts as $contact) {
    echo $contact->name . '<br />';
}

Otherwise, nothing gets output. No $errors, nothing. Any ideas? Oh, I use the correct credentials.

pluijm commented 9 years ago

No output seems to me you're missing a fatal error which is not displayed on screen. Try again with the next lines after the php opening tag: ini_set('display_errors', 1); error_reporting(E_ALL);

adriaansnoeren commented 9 years ago

Indeed... I configured the error reports in .htaccess but they didn't seem to work. Problem was that no timezone was set in php.ini. Got it working now. Thanks for the fast reply!