500 error when attempting to create contact using PHP cURL and json

Hi,

I wonder if anyone else if having issues creating contacts using PHP cURL
and json, or if (more likely) I’m doing something stupid and anyone is able
to see anything obvious / lend me a hand please?!

Updating contacts is working with no issues:
$curl = curl_init($base_url .’/contacts/’. $fid);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
“Authorization: Bearer $token”,
“Accept: application/json”,
“Content-Type: application/json”,
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, ‘SD’);
$curl_response = curl_exec($curl);
curl_close($curl);

Where $fid is the FreeAgent contact id, and $data_string is:

{“contact”:{“organisation_name”:“test”,“first_name”:“Richard”,“last_name”:“Smart”,“email”:"",“phone_number”:"",“address1”:"",“town”:"",“region”:"",“postcode”:"",“address2”:"",“address3”:"",“contact_name_on_invoices”:"",“country”:“United Kingdom”,“sales_tax_registration_number”:"",“uses_contact_invoice_sequence”:“true”}}

But replacing two lines to try to create a contact (and using the same
data) returns a 500:
$curl = curl_init($base_url .’/contacts’);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”);

Here’s my request header from curl_getinfo:
POST /v2/contacts HTTP/1.1
User-Agent: SD
Host: api.sandbox.freeagent.com
Authorization: Bearer token
Accept: application/json
Content-Type: application/json
Content-Length: 321

Is it possible for anyone to point me in the right direction please? Many
thanks!
Richard

Hi Richard,

The “contact_name_on_invoices” field can not be blank as it’s a boolean.
You can either omit the field entirely for the default value (false), or
supply an explicit value if you’d prefer.

This field maps to the “Display Contact Name” option of the contact.

https://lh4.googleusercontent.com/-xLLoeYFwMsM/U5V3cQFVGVI/AAAAAAAAAG0/-0kLJPneb8s/s1600/FreeAgent+%3A+Edit+Contact+2014-06-09+09-58-58+2014-06-09+09-59-29.png

Hope that helps,

Paul.On Sunday, 8 June 2014 23:56:25 UTC+1, Richard Smart wrote:

Hi,

I wonder if anyone else if having issues creating contacts using PHP cURL
and json, or if (more likely) I’m doing something stupid and anyone is able
to see anything obvious / lend me a hand please?!

Updating contacts is working with no issues:
$curl = curl_init($base_url .’/contacts/’. $fid);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
“Authorization: Bearer $token”,
“Accept: application/json”,
“Content-Type: application/json”,
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, ‘SD’);
$curl_response = curl_exec($curl);
curl_close($curl);

Where $fid is the FreeAgent contact id, and $data_string is:

{“contact”:{“organisation_name”:“test”,“first_name”:“Richard”,“last_name”:“Smart”,“email”:"",“phone_number”:"",“address1”:"",“town”:"",“region”:"",“postcode”:"",“address2”:"",“address3”:"",“contact_name_on_invoices”:"",“country”:“United Kingdom”,“sales_tax_registration_number”:"",“uses_contact_invoice_sequence”:“true”}}

But replacing two lines to try to create a contact (and using the same
data) returns a 500:
$curl = curl_init($base_url .’/contacts’);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”);

Here’s my request header from curl_getinfo:
POST /v2/contacts HTTP/1.1
User-Agent: SD
Host: api.sandbox.freeagent.com
Authorization: Bearer token
Accept: application/json
Content-Type: application/json
Content-Length: 321

Is it possible for anyone to point me in the right direction please? Many
thanks!
Richard

Amazing, that did it- many thanks Paul!

Cheers,
RichardOn Monday, 9 June 2014 09:59:54 UTC+1, Paul Smith wrote:

Hi Richard,

The “contact_name_on_invoices” field can not be blank as it’s a boolean.
You can either omit the field entirely for the default value (false), or
supply an explicit value if you’d prefer.

This field maps to the “Display Contact Name” option of the contact.

https://lh4.googleusercontent.com/-xLLoeYFwMsM/U5V3cQFVGVI/AAAAAAAAAG0/-0kLJPneb8s/s1600/FreeAgent+%3A+Edit+Contact+2014-06-09+09-58-58+2014-06-09+09-59-29.png

Hope that helps,

Paul.

On Sunday, 8 June 2014 23:56:25 UTC+1, Richard Smart wrote:

Hi,

I wonder if anyone else if having issues creating contacts using PHP cURL
and json, or if (more likely) I’m doing something stupid and anyone is able
to see anything obvious / lend me a hand please?!

Updating contacts is working with no issues:
$curl = curl_init($base_url .’/contacts/’. $fid);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
“Authorization: Bearer $token”,
“Accept: application/json”,
“Content-Type: application/json”,
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, ‘SD’);
$curl_response = curl_exec($curl);
curl_close($curl);

Where $fid is the FreeAgent contact id, and $data_string is:

{“contact”:{“organisation_name”:“test”,“first_name”:“Richard”,“last_name”:“Smart”,“email”:"",“phone_number”:"",“address1”:"",“town”:"",“region”:"",“postcode”:"",“address2”:"",“address3”:"",“contact_name_on_invoices”:"",“country”:“United Kingdom”,“sales_tax_registration_number”:"",“uses_contact_invoice_sequence”:“true”}}

But replacing two lines to try to create a contact (and using the same
data) returns a 500:
$curl = curl_init($base_url .’/contacts’);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”);

Here’s my request header from curl_getinfo:
POST /v2/contacts HTTP/1.1
User-Agent: SD
Host: api.sandbox.freeagent.com
Authorization: Bearer token
Accept: application/json
Content-Type: application/json
Content-Length: 321

Is it possible for anyone to point me in the right direction please? Many
thanks!
Richard