Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new contact record to Dynamics CRM via REST call

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.

like image 493
Jordan Lev Avatar asked Mar 04 '11 17:03

Jordan Lev


People also ask

How to create custom entity record from contact save?

You can write script on contact save and call your script to create custom entity record. you can look for OData designer to write your query, Or Can use SDK library for the same as suggested. Thanks Reply Necdet Saritasresponded on 8 Mar 2016 4:14 PM

How do I create Recurring Appointments in the Dynamics 365 app?

Recurring appointments are not supported on the Dynamics 365 App for Outlook, Dynamics 365 for phones app, and when you run the web client on your mobile phone web browser. Open the record you want to add the activity to. In the middle of the page, select Activities > More Commands > Appointment. Fill in your information.

How do I take or review customer notes in Dynamics 365?

To save the record, select Save. You can also easily add notes in the activities area. And if you're on the latest version of Dynamics 365 for Customer Engagement, you have the benefits of using OneNote to take or review customer notes from within your Dynamics 365 Customer Engagement (on-premises)app records.

How to add a new field for contact entity?

You could add a new field for contact entity in modern editor: 1. Create a new field for contact entity. open Data -> Entities, (2) choose Contact (3). 2. Add the field to Contact form open Contact (Main) form. (2) 2.3 Switch back to Fields, drag the custom field to section you want.


1 Answers

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)
    );
}
like image 91
stevecomrie Avatar answered Nov 15 '22 23:11

stevecomrie