I have been working with the PHP SDK to connect to the API and create a contact. I have managed to successfully authenticate and get a token just fine. However, I haven’t been able to figure out why I can’t successfully create a contact. I’ve looked over the API documentation quite a bit, and I’m just not sure where I’m going wrong.
Assuming I’ve got the authentication working properly and I’m setting the token on my instantiated $infusionsoft object, here is the code I’m using to try and create a contact:
$contact = array(
'email_addresses' => array(
'email' => 'test@test.com',
'field' => 'EMAIL1'
),
'given_name' => 'John',
'family_name' => 'Doe',
'phone_numbers' => array(
'field' => 'PHONE1',
'number' => '123-123-1234'
)
);
$infusionsoft->contacts()->create($contact);
And here is the error I’m getting (I cleared out the access token - the actual value is correct):
Fatal error: Uncaught exception ‘Infusionsoft\Http\HttpException’ with message 'exception ‘GuzzleHttp\Exception\ClientException’ with message 'Client error: POST https://api.infusionsoft.com/crm/rest/v1/contacts/?access_token=######
resulted in a 400 Bad Request
response: {“message”:“Input could not be converted to a valid request”} ’ in /home/deedclai/public_html/dev/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /home/deedclai/public_html/dev/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /home/deedclai/public_html/dev/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /home/deedclai/public_html/dev/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 /home/deedclai/public_html/dev/vendor/gu in /home/deedclai/public_html/dev/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/GuzzleHttpClient.php on line 77
I have tried numerous other ways to pass in data, and different versions of data to the create() call, but I get the same error every time. Hoping someone can point me in the right direction.
Thank you,