We’ve been using Microsoft Dynamics 2013 at work for a little while now. One thing that’s been on my to-do list since the beginning has been automating the creation of CRM accounts when our internal hosting system had a new account added.
On and off over the past couple of months, I’ve been trying various pieces of sample code dotted here and there and have not managed to get anything working. Until now that is.
The sample code came from a surprising source, Microsoft themselves! 🙂 Hidden away in the Dynamics CRM 2011 SDK is some PHP code. The code as-is is broken and won’t login to a Dynamics 2013 instance that uses Office 365 live-id’s for authentication. However, with a little tweaking it’s possible to get it all working!
Edit Main.php and update the Username, Password and organizationServiceURL variables. When you execute Main.php it should:
- Create a new account
- Update the account with a new name
- If enabled, delete the account
[[email protected] crm]$ php Main.php Array (  => Array ( [name] => Newer Corporation [accountId] => b0d711b3-e629-e411-b376-d89d67631e7c ) ) Array (  => Array ( [name] => Updated Newer [accountId] => b0d711b3-e629-e411-b376-d89d67631e7c ) )
Update 20th Nov 2014: Due to changes of configuration on Microsoft’s servers, you’ll need to update LiveIDManager.php. Comment out the following line:
curl_setopt($cURLHandle, CURLOPT_SSLVERSION , 3);
Rather than specifying SSLv3, we want to allow curl to auto-negotiate the best SSL/TLS version available. Thanks to Django Radonich-Camp for spotting that.