Update contact using Light PHP wrapper

I’m having problems creating a new contact in FreeAgent.

I’m using the Light PHP wrapper for the OAuth 2.0 protocol and have managed to successfully set up oAuth2. I can connect to FreeAgent and successfully retrieve a list of customers. So far, so good. The problem I’ve got is sending data back the other way, i.e. creating a new contact in FreeAgent.

Here’s some code I’ve tried:

require_once($_SERVER['DOCUMENT_ROOT'].'/OAuth2/Client.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/OAuth2/GrantType/IGrantType.php');

$client = new OAuth2\Client($clientid, $secret);

$params = json_encode(array('contact' => array('first-name' => $firstname_unencrypted, 'last-name' => $surname_unencrypted)));
    				
$response = $client->fetch("/contacts", $params, "POST", array('User-Agent' => 'MyApp', 'Accept' => 'application/json', 'Content-type' => 'application/json'));

var_dump($response);

The var_dump returned shows:

array(3) {
  ["result"]=>
  bool(false)
  ["code"]=>
  int(0)
  ["content_type"]=>
  bool(false)
}

I’m pretty sure I’m doing something silly. I’ve tried sending in XML instead of JSON. I’ve tried using just a single array of params rather than the array in an array I’ve got in the sample. I’m going round in circles!

If someone could give me a little nudge in the right direction, I’d be eternally grateful!

Thanks

I’ve fixed this already. Used CURL to send the data and it worked fine!