Closed MichelReij closed 12 years ago
PHP 5.2.17 should be sufficient. Is there an error thrown?
No, not at all.
I did add a require_once at the top of the page:
require_once("Api.php");
With my test page at the same level as Api.php.
Here's my test.php page:
<? require_once("Api.php");
$mbapi = new MoneybirdApi('**_', '@**.com', '_****');
$contact = new MoneybirdContact(); $contact->company_name = 'Company name'; $contact->firstname = 'First name'; $contact->lastname = 'Last name'; $contact->attention = 'For attention of John Doe'; $contact->address1 = 'Address line 1'; $contact->address2 = 'Address line 2'; $contact->zipcode = '1234AA'; $contact->city = 'Amsterdam'; $contact->country = 'Nederland'; $contact->email = 'moneybirdtest@mydomain.tld'; $contact->phone = '0612345678';
$contact = $mbapi->saveContact($contact);
echo 'Contact ID: '.$contact->id;
?>
The user name still has to be the email address, right?
could you post your script here? Please remove your credentials and other private data
Please don't use the short open tag (<?). Always use <?php as this will be the default in PHP 5.3 and above. It could be disabled on your server. If you look at the HTML source in your browser and see your PHP code, the short open tag is disabled
OK, but it does not solve the issue.
I really do appreciate your help, btw! Is it correct that the user name still has to be the email address?
The API logs in just as you would do on the website. If your credentials are invalid, an exception is thrown.
As there is no error, is the text "Contact ID" shown? Please add the following lines on a new line after <? error_reporting(E_ALL); ini_set('display_errors', 1);
OK, now we're getting somewhere... ;-)
Notice: Undefined offset: 1 in /services5/webpages/m/r/mreij.com/public/moneybird/Api.php on line 352
Fatal error: Uncaught exception 'MoneybirdUnknownResponseException' with message 'Unknown response from Moneybird: 0' in /services5/webpages/m/r/mreij.com/public/moneybird/Api.php:297 Stack trace: #0 /services5/webpages/m/r/mreij.com/public/moneybird/Api.php(520): MoneybirdApi->request('contacts', 'POST', Object(MoneybirdContact)) #1 /services5/webpages/m/r/mreij.com/public/moneybird/Api.php(607): MoneybirdApi->saveMbObject(Object(MoneybirdContact), 'contact') #2 /services5/webpages/m/r/mreij.com/public/moneybird/test.php(25): MoneybirdApi->saveContact(Object(MoneybirdContact)) #3 {main} thrown in /services5/webpages/m/r/mreij.com/public/moneybird/Api.php on line 297
Could you test the code on PHP 5.3? 5.2.17 might have issues. I don't have 5.2.17 since it isn't supported by PHP.net anymore
Also, please test if other example do work. E.g. getContacts(). It might be a curl/ssl issue
OK, I transferred the test.php to my NL and echoed the PHP version:
PHP Version: 5.3.8
Notice: Undefined offset: 1 in /var/www/html/moneybird/Api.php on line 352
Fatal error: Uncaught exception 'MoneybirdUnknownResponseException' with message 'Unknown response from Moneybird: 0' in /var/www/html/moneybird/Api.php:297 Stack trace: #0 /var/www/html/moneybird/Api.php(520): MoneybirdApi->request('contacts', 'POST', Object(MoneybirdContact)) #1 /var/www/html/moneybird/Api.php(607): MoneybirdApi->saveMbObject(Object(MoneybirdContact), 'contact') #2 /var/www/html/moneybird/test.php(25): MoneybirdApi->saveContact(Object(MoneybirdContact)) #3 {main} thrown in /var/www/html/moneybird/Api.php on line 297
I will now try getContacts...
This is the new code:
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
require_once("Api.php");
$mbapi = new MoneybirdApi('xxxx', 'xxxx.xxxx@xxxx.com', 'xxxx'); echo("PHP Version: " . phpversion());
$contact = $mbapi->getContacts();
?>
This is the result:
PHP Version: 5.3.8 Notice: Undefined offset: 1 in /var/www/html/moneybird/Api.php on line 352
Fatal error: Uncaught exception 'MoneybirdUnknownResponseException' with message 'Unknown response from Moneybird: 0' in /var/www/html/moneybird/Api.php:297 Stack trace: #0 /var/www/html/moneybird/Api.php(448): MoneybirdApi->request('contacts', 'GET', NULL, NULL) #1 /var/www/html/moneybird/Api.php(575): MoneybirdApi->getMbObjects('contact') #2 /var/www/html/moneybird/test2.php(10): MoneybirdApi->getContacts() #3 {main} thrown in /var/www/html/moneybird/Api.php on line 297
Seems like MoneyBird is returning me something strange, right?
It's not MoneyBird, the same code is working fine at my computer. You can bypass SSL by adding the following line before $mbapi = ... MoneybirdApi::$sslInsecure = true;
Try that to make sure you don't have an SSL issue. If that fails too, please provide me with the output of phpinfo(). You can e-mail it to me at sjors at desjors dot nl if you don't want to post it here
Adding that line solves the issue!
The original test.php page (your first example) now returns: Contact ID: 288054
What does this mean for me? And do you still want the phpinfo mailed to you?
It means that your server is not capable of communicating with MoneyBird over SSL. For testing purposes this is not a big issue, but I wouldn't use it in production (with real login info). I don't know how to solve this. You probably need to update your certificates. I'll check with MoneyBird if they know a sollution
OK, thanks for all your help!
Both my domains are hosted by regular webhosters. The .com domain in the UK with TalkTalkBusiness (formerly Freedom2Surf) and the .nl domain is hosted by Digitalus. Is this an uncommon situation for users of the MoneyBird API?
I've had contact with MoneyBird: A few months ago they installed a new SSL certificate. This certificate uses 256 bit encryption (was 128). On some computers and servers the Certificate Authorize bundle is too old and therefor unable to check it. After updating the CA cert bundle everything sould work fine.
http://curl.haxx.se/docs/sslcerts.html http://curl.haxx.se/docs/caextract.html
Thanks Sjors!
But I presume that this is something that needs to be done by my hosting company?
Correct
Is there a minimum version required of PHP? I am trying to get this new version to work on PHP 5.2.17, but sofar without succes. It seems to stumble on: $contact = $mbapi->saveContact($contact);
In your first example.