Contact Us 1-800-596-4880

Microsoft Dynamics CRM Connector 3.2 - Mule 4

Anypoint Connector for Microsoft Dynamics CRM enables Mule apps to interact with Microsoft Dynamics CRM’s SOAP Organization Service.

For compatibility information and fixed issues, see the release notes.

Before You Begin

To use this connector, you must be familiar with:

  • Microsoft Dynamics CRM API

  • Anypoint Connectors

  • Mule runtime engine (Mule)

  • Elements and global elements in a Mule flow

  • How to create a Mule app using Anypoint Studio (Studio)

Before creating an app, you must have login credentials for Microsoft Dynamics CRM SOAP Organization Service to test your connection to your target resource.

Any created or expired date in the Web service header created by the Microsoft CRM instance must conform to the constraints specified in the Basic Security Profile validation for Web services, http://www.ws-i.org/Profiles/BasicSecurityProfile-1.0.html, as summarized below:

  • A created or expired date must not contain a seconds value with more than three digits to the right of the decimal (milliseconds).

  • A created or expired date that contains a seconds value must specify a seconds value less than 60.

  • A created or expired date must not include the ValueType attribute.

  • A created or expired date must contain time values in UTC format, as specified by the XML Schema type (dateTime).

Add a POM File Depedency

<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-microsoft-dynamics-crm-connector</artifactId>
  <version>x.x.x</version>
  <classifier>mule-plugin</classifier>
</dependency>

Replace x.x.x with the version that corresponds to the connector you are using.

To obtain the most up-to-date pom.xml file information:

  1. Go to Anypoint Exchange.

  2. In Exchange, click Login and supply your Anypoint Platform username and password.

  3. In Exchange, search for <connector-name>.

  4. Select the connector.

  5. Click Dependency Snippets near the upper right of the screen.

Add the Connector to a Studio Project

Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view.

  1. In Studio, create a Mule project.

  2. In the Mule Palette view, click (X) Search in Exchange.

  3. In Add Modules to Project, type crm in the search field.

  4. Click this connector’s name in Available modules.

  5. Click Add.

  6. Click Finish.

Configure the Connector in Studio

  1. Drag the connector to the Studio Canvas.

  2. To create a global element for the connector, set these fields:

    Online Authentication (Default):

    • Username: Enter the Dynamics CRM username.

    • Password: Enter the corresponding password.

    • Organization Service URL: Enter the corresponding organization service URL.

    • Authentication retries: Enter the desired number of retries for authentication.

    • Disable cn check: Choose if you want to bypass SSL Certificates.

      Credentials configuration

Use Case - Microsoft Dynamics CRM Operations Demo

This demo includes the following options:

  • Return all accounts: http://localhost:8081/accounts

  • Query accounts by name containing a substring: http://localhost:8081/query-accounts?name=li

  • Create a new account with the specified name: http://localhost:8081/create-account?name=your-account-name

  • Retrieve account by ID: http://localhost:8081/retrieve-account?accountid={account-guid}

  • Delete an account: http://localhost:8081/delete-account?accountid={account-guid}

  • Return all contacts: http://localhost:8081/contacts

  • Return all contacts for an account: http://localhost:8081/contacts-by-account?accountid={account-guid}

  • Associate a contact to an account: http://localhost:8081/associate?accountid={account-guid}&contactid={contact-guid}

  • Disassociate a contact from an account: http://localhost:8081/disassociate?accountid={account-guid}&contactid={contact-guid}

  • Create an opportunity: http://localhost:8081/create-opportunity?accountid={account-guid}&contactid={contact-guid}

  • Query opportunities by parent account: http://localhost:8081/opportunities-by-account?accountid={account-guid}

  • Activate an account by executing the SetState operation: http://localhost:8081/activate-account?accountid={account-guid}

  • Deactivate an account by executing the SetState operation: http://localhost:8081/deactivate-account?accountid={account-guid}

  • Create multiple entities in a single request: http://localhost:8081/create-multiple

  • Update the property 'Description' of multiple contacts in a single request: http://localhost:8081/update-multiple

  • Retrieve updated contacts: http://localhost:8081/updated-contacts

  • Delete multiple contacts in a single request: http://localhost:8081/delete-multiple

Use Case Studio Visual Flow

Studio app flows for all accounts, query account by name, and create account
Studio app flows for deleting account, retrieving account, all contacts, and getting associated contacts
Studio app flows for associate contact to account, disassociate contact to account, get opportunities, and create opportunity
Studio app flows for execute and activate account, execute and deactivate account, create multiple contacts, and delete multiple contacts
Studio app flows for updating multiple contacts and retrieving and updating contacts

Use Case XML Flow

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
    xmlns:microsoft-dynamics-crm="http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm"
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
    http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http
    http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm
    http://www.mulesoft.org/schema/mule/microsoft-dynamics-crm/current/mule-microsoft-dynamics-crm.xsd
    http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
    <configuration-properties file="mule-app.properties"/>

    <http:listener-config
        name="HTTP_Listener_config"
        doc:name="HTTP Listener config" >
        <http:listener-connection
        host="localhost"
        port="8081" />
    </http:listener-config>
    <microsoft-dynamics-crm:dynamics-crm-config
        name="Microsoft_Dynamics_CRM_Dynamics_CRM"
        doc:name="Microsoft Dynamics CRM Dynamics CRM" >
        <microsoft-dynamics-crm:online-connection
            username="${username}"
            password="${password}"
            organizationServiceUrl="${organizationServiceUrl}"
            authenticationRetries="${authenticationRetries}" />
    </microsoft-dynamics-crm:dynamics-crm-config>
    <flow name="crm-all-accounts"  >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/accounts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT accountid,name,statecode,statuscode FROM account]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-query-account-by-name"  >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/query-accounts"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT accountid,name,statecode,statuscode FROM account WHERE name LIKE '%" ++ attributes.queryParams.name ++ "%'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-account"/>
        <ee:transform doc:name="Transform Message"  >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "name": attributes.queryParams.name
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create
            logicalName="account"
            doc:name="Create"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-delete-account"
        config-ref="HTTP_Listener_config"
        path="/delete-account"/>
        <microsoft-dynamics-crm:delete
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            doc:name="Delete"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM" />
    </flow>
    <flow name="crm-retrieve-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/retrieve-account"/>
        <microsoft-dynamics-crm:retrieve
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            doc:name="Retrieve"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-all-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/contacts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT accountid,contactid,firstname,lastname FROM contact]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-get-associated-contacts" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/contacts-by-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT contactid, accountidname, parentcustomerid_referenceto_account FROM contact WHERE parentcustomerid_referenceto_account = '" ++ attributes.queryParams.accountid ++ "'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-associate-contact-to-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/associate"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[
    attributes.queryParams.contactid
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:associate
            logicalName="account"
            relatedEntitiesIds="#[payload]"
            doc:name="Associate"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            relationshipSchemaName="contact_customer_accounts"
            id="#[attributes.queryParams.accountid]"
            relationshipEntityRoleIsReferenced="true"/>
    </flow>
    <flow name="crm-disassociate-contact-to-account" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/disassociate"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
[
    attributes.queryParams.contactid
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:disassociate
            doc:name="Disassociate"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            logicalName="account"
            id="#[attributes.queryParams.accountid]"
            relationshipEntityRoleIsReferenced="true"
            relationshipSchemaName="contact_customer_accounts"
            relatedEntitiesIds="#[payload]"/>
    </flow>
    <flow name="crm-get-opportunities" >
        <http:listener doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/opportunities-by-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "query" : "dsql:SELECT accountid_referenceto_account,accountidname,customerid_referenceto_contact,name,parentaccountid_referenceto_account FROM opportunity WHERE parentaccountid_referenceto_account = '" ++ attributes.queryParams.accountid ++ "'"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[#[payload.query]]]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-opportunity" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-opportunity"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "parentaccountid_referenceto_account": attributes.queryParams.accountid,
    "contactid_referenceto_contact": attributes.queryParams.contactid,
    "name": "unique opportunity",
    "timeline": 2
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create
            logicalName="opportunity"
            doc:name="Create"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-execute-activate-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/activate-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
    "entityMoniker": {
        "id": {
            "value": attributes.queryParams.accountid,
        },
        "logicalName": "account"
    },
    "state": {
        "value": 0
    },
    "status": {
        "value": 1
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:execute
            requestName="SetState" doc:name="Execute"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-execute-deactivate-account" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/deactivate-account"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
    "entityMoniker": {
        "id": {
            "value": attributes.queryParams.accountid,
        },
        "logicalName": "account"
    },
    "state": {
        "value": 1
    },
    "status": {
        "value": 2
    }
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:execute
            doc:name="Execute"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"
            requestName="SetState"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-create-multiple-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/create-multiple"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
[
    {
      "fullname":"Contact1",
      "address1_city":"DemoCity",
      "description":"Demo contact 1"
    },
    {
      "fullname":"Contact2",
      "address1_city":"DemoCity",
      "description":"Demo contact 2"
    },
    {
      "fullname":"Contact3",
      "address1_city":"DemoCity",
      "description":"Demo contact 3"
    }
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:create-multiple
            logicalName="contact"
            doc:name="Create multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-delete-multiple" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/delete-multiple"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
payload.*contactid
]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:delete-multiple
            logicalName="contact"
            ids="#[payload]"
            doc:name="Delete multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM"/>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-update-multiple-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/update-multiple"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid,description FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
updates: payload map (item, index) -> {
      "contactid" : item.contactid,
      "description" : "Updated Description"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <microsoft-dynamics-crm:update-multiple
            logicalName="contact"
            doc:name="Update multiple"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:list-of-attributes ><![CDATA[#[payload.updates]]]></microsoft-dynamics-crm:list-of-attributes>
        </microsoft-dynamics-crm:update-multiple>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="crm-retrieve-update-contacts" >
        <http:listener
            doc:name="Listener"
            config-ref="HTTP_Listener_config"
            path="/updated-contacts"/>
        <microsoft-dynamics-crm:retrieve-multiple-by-query
            doc:name="Retrieve multiple by query"
            config-ref="Microsoft_Dynamics_CRM_Dynamics_CRM">
            <microsoft-dynamics-crm:query ><![CDATA[dsql:SELECT contactid,description FROM contact WHERE address1_city = 'DemoCity']]></microsoft-dynamics-crm:query>
        </microsoft-dynamics-crm:retrieve-multiple-by-query>
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>
View on GitHub