10
votes

I know nothing about how Dynamics works, nor do I know anything about its data model (nor do I understand its lingo, so I apologize in advance if I'm using the wrong terms).

I am building a website and when someone fills out a form on that site, a new record needs to be created in Dynamics CRM (I believe the latest version which is 2011).

This website is built in PHP so much of the sample code provided by MS doesn't apply. Ideally what I'm looking for is some instructions or a link to a tutorial that looks like this:

  1. Make a POST request to this url: http://myinstallation.com/address/to/rest/endpoint
  2. Pass it these parameters:
    • 'password': application password
    • 'firstName': contact first name
    • 'lastName': contact last name
    • 'address1': First line of street address etc. etc.
  3. It will return the following info as a JSON string:
    • 'error code': 0 for success, otherwise error number
    • 'error message': description of error (if any)

I know that perhaps there isn't a straightforward "contact" concept in the CRM but rather some combination of "opportunity" and "person" and "organization". And I know that perhaps you don't just send it a password but rather some authentication token or cookie data. And I know that it might require a SOAP call instead of a REST call (although it seems the latest version supports REST, which I'd prefer because it's simpler). And I know that it probably doesn't return JSON strings. What I posted above is just an example of the format that my ideal answer would look like (not trying to be demanding, just that I know things can get "lost in translation" between the MS and PHP worlds sometimes so hopefully that helps explain what a useful answer to my feeble brain looks like).

Or perhaps I'm totally off-base and doing this kind of thing isn't possible without tons of customization on the Dynamics side?

BTW, I am not currently concerned with "2-way synchronization" so I just need to tell the CRM there's a new contact (ideally it would automatically flag records it thinks are duplicates, but that's not required).

Thanks for any guidance or assistance you can provide.

2

2 Answers

3
votes

I had this exact same problem and after a bunch of hair pulling (during which time I came across your post here) I found this guy, who offers a pre-built PHP library for a very reasonable price that does just what you need:

http://www.zenithies.org/articles/articles/6/microsoft-dynamics-crm-4-0-php-integration-offer.html

I'm in the process of integrating his code with my production application, but here is the interface you deal with, very nearly what you were looking for:

$bridge = new CrmExt();
$bridge->liveUser = '[email protected]';
$bridge->livePassword = 'password';
$bridge->crmDiscoveryHost = 'domain.crm.dynamics.com';
$bridge->crmDiscoveryHostHttps = true;
$bridge->crmAddress = 'domain.crm.dynamics.com';
$bridge->crmHost = 'domain.api.crm.dynamics.com';
$bridge->crmHostHttps = true;

try {
    $bridge->connnect();

    $newContact = array(
        'firstname' => 'John',
        'lastname' => 'Doe',
        'emailaddress1' => '[email protected]',
        'telephone1' => '+420 000 000 000 000',
        // etc ..
    );

    // This will send account into crm
    $newContactId = $bridge->pushContact( $newContact );
} catch (Exception $e) {
    printf(
        '<h1>Error:</h1><ul><li>%s</li></ul><pre>%s</pre>',
        $e->getMessage(),
        $bridge->dump(true)
    );
}
-1
votes

i used this class: https://github.com/Ben-Speakman/PHP-Dynamics-Online-CRM-2011-SOAP-Class

and request like this:

$request = '<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                           <request i:type="a:CreateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
                            <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                           <a:KeyValuePairOfstringanyType>
                           <b:key>Target</b:key>
                            <b:value i:type="a:Entity">
                            <a:Attributes>
                          <a:KeyValuePairOfstringanyType>
                            <b:key>firstname</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">name</b:value>
                           </a:KeyValuePairOfstringanyType>
                           <a:KeyValuePairOfstringanyType>
                            <b:key>lastname</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">lastname</b:value>
                           </a:KeyValuePairOfstringanyType>
                          <a:KeyValuePairOfstringanyType>
                            <b:key>department</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">department_name</b:value>
                           </a:KeyValuePairOfstringanyType>
                            <a:KeyValuePairOfstringanyType>
                            <b:key>emailaddress1</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">[email protected]</b:value>
                           </a:KeyValuePairOfstringanyType>
                            <a:KeyValuePairOfstringanyType>
                            <b:key>telephone1</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">00112233</b:value>
                           </a:KeyValuePairOfstringanyType>
                         <a:KeyValuePairOfstringanyType>
                            <b:key>description</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">bla bla</b:value>
                           </a:KeyValuePairOfstringanyType>
                           <a:KeyValuePairOfstringanyType>
                          <b:key>address1_country</b:key>
                          <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">My country</b:value>
                           </a:KeyValuePairOfstringanyType>
                                         </a:Attributes>
                                         <a:EntityState i:nil="true" />
                                         <a:FormattedValues />
                                         <a:Id>'.$dynamicsClient->create_guid().'</a:Id>
                                         <a:LogicalName>contact</a:LogicalName>
                                         <a:RelatedEntities />
                                       </b:value>
                                     </a:KeyValuePairOfstringanyType>
                                   </a:Parameters>
                                   <a:RequestId i:nil="true" />
                                   <a:RequestName>Create</a:RequestName>
                                 </request>
                               </Execute>';

                    $dynamicsClient->sendQuery($request);