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