Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Microsoft Dynamics 365 Connector

Select

Version: 1.0.0

The Microsoft Dynamics 365 Customer Relationship Management (CRM) connector for Anypoint platform enables integration with Microsoft Dynamics 365 Web API.

This connector lets you perform operations to:

  • Authorize or unauthorize server access.

  • Create, update, and delete entities.

  • Retrieve a single entity or query multiple entities.

  • Associate and disassociate entities.

  • Execute actions.

Prerequisites

This document assumes that you are familiar with Mule, Anypoint Connectors, and the Anypoint Studio Essentials. To increase your familiarity with Studio, consider completing one or more Anypoint Studio Tutorials. Further, this page assumes that you have a basic understanding of Mule flows and Mule Global Elements.

Obtain a client ID and secret for your app by logging into the Microsoft Azure Active Directory portal at portal.azure.com.

Before starting:

  • You need access to a Microsoft Dynamics 365 instance (online or on-premise) leveraged by Azure Active Directory; that is, Azure Active Directory is the Identity Provider that provides access to an application.

  • Set the DataSense timeout in Anypoint Studio to a duration longer than 500 seconds. You can set this value from the Preferences menu > Anypoint Studio > DataSense > DataSense Connection Timeout.

About Connector Terminology

  • Actions - Operations that allow side effects, such as data modification, and cannot be further composed to avoid non-deterministic behavior.

  • Complex types - Keyless named structured types consisting of a set of properties. Complex types are commonly used as property values in model entities, or as parameters or return values for operations.

  • Entities - Instances of entity types, for example, an account or an opportunity.

  • Entity sets - Named collections of entities, for example, an account is an entity set containing account entities. An entity’s key uniquely identifies the entity within an entity set.

  • Entity types - Named structured types with a key. Entity types define the named properties and relationships of an entity, and may derive by single inheritance from other entity types.

  • Enumeration types or Enum types - Named primitive types whose values are named constants with underlying integer values.

  • Functions - Operations that do not have side effects and may support further composition, for example, with additional filter operations, functions or an action.

To Install and Configure the Connector

  1. Download and install Java 8 (latest version) or Java 7 (deprecated by Oracle).

  2. Click the Anypoint Exchange 365-exchange-icon icon in the taskbar, search for 365, and follow the prompts to install the connector.

Note: JCE is not required for this connector.

To Create a New Mule Project Using the Anypoint Studio Visual Editor

  1. In Anypoint Studio, click File > New > Mule Project.

  2. Specify a Project Name and click Finish.

  3. Search for "http" and drag the HTTP connector to the canvas. Click the green plus sign next to Connector Configuration, and click OK in the menu to accept the default values.

  4. Search for "365" and drag the Microsoft Dynamics 365 CRM connector to the canvas. Click the green plus next to Connector Configuration, and specify your access credentials.

  5. Click a connection strategy for authentication:

    • Microsoft Dynamics 365 OAuth 2.0 Connection

    • Microsoft Dynamics 365 OAuth 2.0 Username-Password

To Configure OAuth 2.0 Connection

This configuration provides access to the Microsoft Dynamics 365 Web API.

  1. Click the green plus sign to the right of Connector Configuration.

  2. Provide the Client ID and Secret values.

  3. Choose an action if a token is not provided:

    1. EXCEPTION (Default) - Causes an exception if there is no token.

    2. STOP_FLOW - Stops running the Mule project if there is no token.

  4. If needed, set the OAuth tab in Global Element Properties as described in Using a Connector to Access an OAuth API.

To implement OAuth 2.0 in the Connection configuration, you need to use Mule Runtime 3.6.5, ESB 3.7.6 or 3.8.5, or newer versions.

To Configure OAuth 2.0 Username-Password

  1. Click the green plus sign to the right of Connector Configuration.

  2. Provide the following credentials to enable access to your Microsoft Dynamics 365 server:

    • Client ID - The application ID assigned to your app when you registered it with Azure Active Directory. You can find this in the Azure Portal. Click Active Directory, click the directory, choose the application, and click Configure.

    • Client Secret - The application secret that you created in the app registration portal for your app. This should not be used in a native app, because client secrets cannot be reliably stored on devices. This is required for web apps and web APIs, which have the ability to store the client secret securely on the server side.

    • Username - Username used to initialize the session.

    • Password - Password used to authenticate the user.

    • Resource - The application ID URI of the web API (secured resource). This must be the root URI, without specifing the CRM version. Example: https://YOUR_ORG.crm.dynamics.com/

    • Token Request Endpoint - The token endpoint that is called to get the access token. Example: https://login.windows.net/TENANT_ID/oauth2/token where TENANT_ID is the Azure Active Directory ID.

    • Read Timeout - The duration in milliseconds that the consumer waits for a response before timing out. Zero (0) means wait forever.

    • Connection Timeout - Specifies the duration in milliseconds that the consumer tries to establish a connection before timing out. Zero (0) means wait forever.

  3. Click Test Connection to ensure that your credentials are accepted at the server endpoint.

  4. If present, click Enable DataSense to let your application acquire metadata from the server.

For information on setting the Pooling Profile tab, see About Pooling Profiles.

For information on setting the Reconnection tab, see Configuring Reconnection Strategies.

To Run a Flow

  1. In Package Explorer, right click your project’s name, and click Run As > Mule Application.

  2. Check the console to see when the application starts. You should see messages such as these if no errors occur:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
************************************************************
INFO  2017-05-14 22:12:42,003 [main] org.mule.module.launcher.DeploymentDirectoryWatcher:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mule is up and kicking (every 5000ms)                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2017-05-14 22:12:42,006 [main] org.mule.module.launcher.StartupSummaryDeploymentListener:
**********************************************************
*  - - + DOMAIN + - -               * - - + STATUS + - - *
**********************************************************
* default                           * DEPLOYED           *
**********************************************************

************************************************************************
* - - + APPLICATION + - -   * - - + DOMAIN + - -  * - - + STATUS + - - *
************************************************************************
* myapp                     * default             * DEPLOYED           *
************************************************************************

To Configure Connector Operations

To Authorize Access to the Dynamics 365 Server

  1. Set Operation to Authorize (OAuth 2.0 Connection only].

  2. Leave the value for the State field empty, it is handled internally by Mule.

  3. Provide the Access Token URL given to you by the service provider.

  4. Provide the endpoint (required) that issues the token: Example: https://login.windows.net/TENANT/oauth2/token, where TENANT is the Azure Active Directory ID.

  5. Provide the Authorization URL (required) - Indicates where the resource owner is redirected to grant authorization to the connector. Example: https://login.microsoftonline.com/TENANT/oauth2/authorize, where TENANT is the Azure Active Directory ID.

  6. Provide the access token ID (required) - The ID of the access token that’s used to identify the call

  7. Specify the Scope (required) - For OpenID Connect, the scope must include the openid, which translates to login permission in the consent UI.

  8. Specify the Response_mode (required) - This field specifies the method to use to send the resulting token back to your app. To work with Mule, the value must be query.

  9. Specify the Resource (required) - This is the App ID URI of the web API (secured resource). To find the App ID URI of the web API, in the Azure Portal, click Active Directory, click the directory, click the application and then click Configure. Example: https://YOUR_ORG.crm.dynamics.com/.

To Unauthorize Access from the Dynamics 365 Server

  1. Set Operation to Unauthorize (OAuth 2.0 Connection only).

  2. Provide the Access Token URL that you used to authorize access to the Microsoft Dynamics 365 server.

To Create an Entity

  1. Set Operation to Create.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Define optional attributes for the default, from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Create Multiple Entities

  1. Set Operation to Create Multiple.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Click Use Single Transaction to indicate that if the transaction fails, the transaction is rolled back.

  4. Click 365-add-expression-icon to add a MEL expression for the Logical Name attribute.

  5. Define optional attributes from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Delete an Entity

  1. Set Operation to Delete.

  2. Specify a MEL expression for the ID field.

  3. Specify a logical name (required).

To Delete Multiple Entities

  1. Set Operation to Delete Multiple.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Define optional attributes for the default, from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Disassociate an Entity

  1. Set Operation to Disassociate.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Define optional attributes for the default, from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Do an Action

  1. Set Operation to Do Action.

  2. Specify the Action Name (required).

  3. Specify the Bounded Entity ID.

  4. Specify the Bounded Entity Type.

  5. Define optional attributes for the default, from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Invoke the Web API

  1. Set Operation to Invoke.

  2. Specify a URI or MEL expression for the Web API.

  3. Speciy an HTTP method (required): DELETE, GET, PATCH, POST, or PUT.

  4. Specify the request HTTP Headers from the expression or manually.

  5. Specify the JSON string value (required) that is placed in the body of the request.

To Retrieve an Entity

  1. Set Operation to Retrieve.

  2. Specify a MEL expression for the ID field.

  3. Specify a Logical Name (required).

To Retrieve Multiple Entities

  1. Set Operation to Retrieve Multiple.

  2. Specify the Data Query URL or MEL expression for what to retrieve.

  3. Specify the Paging Fetch Size in pages to retrieve. The default is 100 pages.

To Retrieve Multiple Entities by Query

  1. Set Operation to Retrieve Multiple By Query.

  2. Specify the query language.

  3. Configure the Query for what you want to retrieve. For more information on DataSense queuries, see DataSense Query Language.

  4. Specify the Paging Fetch Size in pages to retrieve. The default is 100 pages.

To Update an Entity

  1. Set Operation to Update.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Define optional attributes for the default, from a MEL expression, or manually set attributes as one or more key and value Map pairs.

To Update Multiple Entities

  1. Set Operation to Update Multiple.

  2. Specify the Logical Name (required), which is the name of the schema in lowercase.

  3. Click Use Single Transaction to indicate that if the transaction fails it is rolled back.

  4. Click 365-add-expression-icon to add a MEL expression for the Logical Name attribute.

  5. Define optional attributes for the default or manually set attributes as one or more key and value Map pairs.

Example: Microsoft Dynamics 365

This example demonstrates the use of Microsoft Dynamics 365 Connector.

To build and run this demo project, you need:

  • Anypoint Studio with at least the Mule 3.5 Runtime.

  • Microsoft Dynamics 365 Connector v1.0.0 or higher.

  • Dynamics 365 leveraged by Azure Active Directory.

To Test the Flow

  1. Import the demo project into your workspace using Anypoint Exchange or using the Import command in the File menu.

  2. Specify your OAuth 2 credentials for OAuth 2 Username-Password configuration in the /src/main/app/mule-app.properties file:

    • dynamics365.username - Username used to initialize the session.

    • dynamics365.password - Password used to authenticate the user.

    • dynamics365.resource - The App ID URI of the web API, which is a secured resource. The resource must be a root URI that does not specify the CRM version. Example: https://YOUR_ORG.crm.dynamics.com/

    • dynamics365.clientId - The application ID assigned to your app when you registered it with Azure Active Directory. You can find this in the Azure Portal. Click Active Directory, click the directory, choose the application, and click Configure.

    • dynamics365.clientSecret - The application secret that you created in the app registration portal for your app. This should not be used in a native app, because a client secret cannot be reliably stored on a device. The client secret is required for web apps and web APIs, which have the ability to store the client secret securely on the server side.

    • dynamics365.tokenRequestEndpoint - The token endpoint to call to get an access token.
      Example: +https://login.windows.net/TENANT_ID/oauth2/token where TENANT_ID is the Azure Active Directory ID.

  3. Specify DataSense Connection Timeout with more than 200 seconds because the connector makes several requests to provide DataSense information.

  4. Run the project in Studio.

  5. Type 0.0.0.0:8081 in your browser to access the selection menu of the demo.

  6. Optionally you can configure the Connection Timeout and Read Timeout. The Connection Timeout is the timeout in making the initial connection with the server. The Read Timeout is the timeout on waiting to read data from the server.

You can use the selection menu from http://0.0.0.0:8081 to test the flows or you can POST JSONs using a tool like curl, or any other tool (Chrome/Mozilla Firefox extensions) that lets you POST a body when calling the URL.

Example: Parse Template

Parses the template.

365-demo-parse-template


          
       
1
2
3
4
5
<flow name="PARSE_DEMO_TEMPLATE">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <parse-template location="form.html" doc:name="Parse Template"/>
    <set-property propertyName="content-type" value="text/html" encoding="US-ASCII" mimeType="text/html" doc:name="Property"/>
</flow>

Example: Create Empty Contact

Creates an empty contact entity that is required later in other flows.

GET - The HTTP endpoint listens to the following URL: http://0.0.0.0:8081/createContact

365-demo-create-empty-contact


          
       
1
2
3
4
5
6
<flow name="CREATE_EMPTY_CONTACT_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/createContact" doc:name="HTTP"/>
    <logger message="Requested 'Create Contact Operation'" level="INFO" doc:name="Logger"/>
    <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="contact" doc:name="Microsoft Dynamics 365"/>
    <logger message="Received Response from 'Create Contact Operation'" level="INFO" doc:name="Logger"/>
</flow>

Example: Create Empty Opportunity

Creates an empty opportunity entity that is required later in other flows.

GET - The HTTP endpoint listens at: http://0.0.0.0:8081/createOpportunity

365-demo-create-empty-oppo


          
       
1
2
3
4
5
6
<flow name="CREATE_EMPTY_OPPORTUNITY_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/createOpportunity" doc:name="HTTP"/>
    <logger message="Requested 'Create Opportunity Operation'" level="INFO" doc:name="Logger"/>
    <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="opportunity" doc:name="Microsoft Dynamics 365"/>
    <logger message="Received Response from 'Create Opportunity Operation'" level="INFO" doc:name="Logger"/>
</flow>

Example: Create Acccount

Creates an account with specified attributes and also associates the account with a contact.

POST - HTTP endpoint listens at: http://0.0.0.0:8081/createAccount

Request example:


          
       
1
2
{"AccountName":"Test Account Name","CreditOnHold":true,
"CreditLimit":1000,"ContactID":"CONTACT_ID"}`

365-demo-create-account


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<flow name="CREATE_ACCOUNT_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/createAccount"
    doc:name="HTTP"/>
    <logger message="Requested 'Create Account Operation'" level="INFO"
    doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        name: payload.AccountName,
        creditonhold: payload.CreditOnHold,
        creditlimit: payload.CreditLimit,
        "primarycontactid@odata.bind": "/contacts(" ++ payload.ContactID ++ ")"
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password"
     logicalName="account" doc:name="Microsoft Dynamics 365">
        <dynamics365:attributes ref="#[payload]"/>
    </dynamics365:create>
    <logger message="Received Response from 'Create Account Operation'" level="INFO"
    doc:name="Logger"/>
</flow>

Example: Create Multiple Entities

Creates multiple entities of the same type in a single batch request.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/createMultipleAccounts

Request example:


          
       
1
2
[{"AccountName":"Account Name 1","CreditOnHold":true,"CreditLimit":1500},
{"AccountName":"Account Name 2","CreditOnHold":false,"CreditLimit":2000}]

365-demo-create-multi-ents


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<flow name="CREATE_MULTIPLE_ENTITIES_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/createMultipleAccounts" doc:name="HTTP"/>
    <logger message="Requested 'Create Multiple Accounts Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%input payload application/json
%output application/java
---
payload map {
      name: $.AccountName,
      creditlimit : $.CreditLimit,
      creditonhold : $.CreditOnHold
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:create-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
        <dynamics365:attributes-list ref="#[payload]"/>
    </dynamics365:create-multiple>
    <logger message="Received Response from 'Create Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Update Entity

Updates an account with specified attributes.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/updateAccount

Request example:

{"EntityId":"ENTRY_ID","AccountName":"Updated Name","CreditLimit":1500}

365-demo-update-entity


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<flow name="UPDATE_ENTITY_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/updateAccount" doc:name="HTTP"/>
    <logger message="Requested 'Update Entity Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        entityId: payload.EntityId,
        attributes: {
                creditlimit: payload.CreditLimit,
                name: payload.AccountName
        }
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:update config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
        <dynamics365:attributes ref="#[payload]"/>
    </dynamics365:update>
    <logger message="'Update Entity Operation' has ended with success" level="INFO" doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Update Multiple Entities

Updates multiple entities of the same type in a single batch request.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/updateMultipleAccounts

Request example:


          
       
1
2
[{"EntityId":"ENTRY_ID","AccountName":"Updated Name 1"},
{"EntityId":"ENTRY_ID","AccountName":"Updated Name 2"}]

365-demo-update-multi-ents


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<flow name="UPDATE_MULTIPLE_ENTITIES_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/updateMultipleAccounts" doc:name="HTTP"/>
    <logger message="Requested 'Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%input payload application/json
%output application/java
---
payload map {
        entityId: $.EntityId,
        attributes: {
                name: $.AccountName
        }
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:update-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
        <dynamics365:attributes-list ref="#[payload]"/>
    </dynamics365:update-multiple>
    <logger message="Received Response from 'Update Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Delete Entity

Deletes an entity of a specified type.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/deleteAccount

Request example:

{"EntityId":"ENTRY_ID"}

365-demo-delete-entity


          
       
1
2
3
4
5
6
7
8
9
10
11
12
<flow name="DELETE_ENTITY_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/deleteAccount" doc:name="HTTP"/>
    <logger message="Requested 'Delete Entitiy Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload.EntityId]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:delete config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365"/>
    <logger message="'Delete Entity Operation' has ended with success" level="INFO" doc:name="Logger"/>
</flow>

Example: Retrieve Entity

Retrieves an entity of a specified type.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/retrieveAccount

Request example:

{"EntityId":"ENTRY_ID"}

365-demo-retrieve-entity


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
<flow name="RETRIEVE_ENTITY_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccount" doc:name="HTTP"/>
    <logger message="Requested 'Retrieve Entitiy Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload.EntityId]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:retrieve config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365"/>
    <logger message="Received Response from 'Retrieve Entitiy Operation'" level="INFO" doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Retrieve Entities by URL

Retrieves multiple entities based on the URL request.

GET - The HTTP endpoint listens at: http://0.0.0.0:8081/retrieveAccountsByURL

365-demo-retrieve-entities-by-url


          
       
1
2
3
4
5
6
7
8
9
<flow name="RETRIEVE_ENTITIES_BY_URL_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccountsByURL" doc:name="HTTP"/>
    <logger message="Requested 'Retrieve Multiple Operation'" level="INFO" doc:name="Logger"/>
    <dynamics365:retrieve-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password"
     dataQueryURL="${dynamics365.resource}/api/data/v8.2/accounts?$select=name,accountnumber&amp;$top=3"
      doc:name="Microsoft Dynamics 365"/>
    <logger message="Received Response from 'Retrieve Multiple Operation'" level="INFO" doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Retrieve Entities by Query

Retrieves multiple entities based on Datasense Query Language.

GET - The HTTP endpoint listens at: http://0.0.0.0:8081/retrieveAccountsByQuery

365-demo-retrieve-entities-by-query


          
       
1
2
3
4
5
6
7
8
9
<flow name="RETRIEVE_ENTITIES_BY_QUERY_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccountsByQuery" doc:name="HTTP"/>
    <logger message="Requested 'Retrieve Multiple By Query Operation'" level="INFO" doc:name="Logger"/>
    <dynamics365:retrieve-multiple-by-query config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password"
     query="dsql:SELECT accountid,accountnumber,name FROM account LIMIT 2" doc:name="Microsoft Dynamics 365"/>
    <logger message="Received Response from 'Retrieve Multiple By Query Operation'" level="INFO"
     doc:name="Logger"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

Example: Disassociate Entities

Dissasociates entities. Provide the ID of the entity upon which the request was made and the keys to dissasociate.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/disassociateEntities

Request example:

{"EntityId":"ENTRY_ID","EntityLinkKeys":["primarycontactid"]}

365-demo-disassociate-entities


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<flow name="DISASSOCIATE_ENTITIES_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/disassociateEntities" doc:name="HTTP"/>
    <logger level="INFO" doc:name="Logger" message="Requested 'Dissasociate Entities Operation'"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        entityId: payload.EntityId,
        attributes: payload.EntityLinkKeys
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:disassociate config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
        <dynamics365:attributes ref="#[payload]"/>
    </dynamics365:disassociate>
    <logger level="INFO" doc:name="Logger" message="Finished 'Dissasociate Entities Operation' with success"/>
</flow>

Example: Do Action

Calls the WinOpportunity Action.

POST - The HTTP endpoint listens at: http://0.0.0.0:8081/doAction

Request example:

{"Subject":"Won Opportunity","Status":3,"OpportunityId":"OPPORTUNITY_ID"}

365-demo-do-action


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<flow name="DO_ACTION_DEMO">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/doAction" doc:name="HTTP"/>
    <logger message="Requested 'Do Action Operation'" level="INFO" doc:name="Logger"/>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        OpportunityClose: {
                subject: payload.Subject,
                "opportunityid@odata.bind": "/opportunities(" ++ payload.OpportunityId ++ ")"
        },
        Status: payload.Status
}]]></dw:set-payload>
    </dw:transform-message>
    <dynamics365:do-action config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" actionName="WinOpportunity" doc:name="Microsoft Dynamics 365"/>
    <logger message="Finished 'Do Action Operation'" level="INFO" doc:name="Logger"/>
</flow>

Example XML Flow


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:dynamics365="http://www.mulesoft.org/schema/mule/dynamics365" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
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/dynamics365 http://www.mulesoft.org/schema/mule/dynamics365/current/mule-dynamics365.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <dynamics365:config-oauth-user-pass name="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" clientId="${dynamics365.clientId}" username="${dynamics365.username}" password="${dynamics365.password}" resource="${dynamics365.resource}" clientSecret="${dynamics365.clientSecret}" tokenRequestEndpoint="${dynamics365.tokenRequestEndpoint}" doc:name="Microsoft Dynamics 365: OAuth 2.0 Username-Password"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="PARSE_DEMO_TEMPLATE">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <parse-template location="form.html" doc:name="Parse Template"/>
        <set-property propertyName="content-type" value="text/html" encoding="US-ASCII" mimeType="text/html" doc:name="Property"/>
    </flow>
    <flow name="CREATE_EMPTY_CONTACT_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/createContact" doc:name="HTTP"/>
        <logger message="Requested 'Create Contact Operation'" level="INFO" doc:name="Logger"/>
        <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="contact" doc:name="Microsoft Dynamics 365"/>
        <logger message="Received Response from 'Create Contact Operation'" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="CREATE_EMPTY_OPPORTUNITY_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/createOpportunity" doc:name="HTTP"/>
        <logger message="Requested 'Create Opportunity Operation'" level="INFO" doc:name="Logger"/>
        <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="opportunity" doc:name="Microsoft Dynamics 365"/>
        <logger message="Received Response from 'Create Opportunity Operation'" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="CREATE_ACCOUNT_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/createAccount" doc:name="HTTP"/>
        <logger message="Requested 'Create Account Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        name: payload.AccountName,
        creditonhold: payload.CreditOnHold,
        creditlimit: payload.CreditLimit,
        "primarycontactid@odata.bind": "/contacts(" ++ payload.ContactID ++ ")"
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:create config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
            <dynamics365:attributes ref="#[payload]"/>
        </dynamics365:create>
        <logger message="Received Response from 'Create Account Operation'" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="CREATE_MULTIPLE_ENTITIES_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/createMultipleAccounts" doc:name="HTTP"/>
        <logger message="Requested 'Create Multiple Accounts Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%input payload application/json
%output application/java
---
payload map {
      name: $.AccountName,
      creditlimit : $.CreditLimit,
      creditonhold : $.CreditOnHold
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:create-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
            <dynamics365:attributes-list ref="#[payload]"/>
        </dynamics365:create-multiple>
        <logger message="Received Response from 'Create Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="UPDATE_ENTITY_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/updateAccount" doc:name="HTTP"/>
        <logger message="Requested 'Update Entity Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        entityId: payload.EntityId,
        attributes: {
                creditlimit: payload.CreditLimit,
                name: payload.AccountName
        }
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:update config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
            <dynamics365:attributes ref="#[payload]"/>
        </dynamics365:update>
        <logger message="'Update Entity Operation' has ended with success" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="UPDATE_MULTIPLE_ENTITIES_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/updateMultipleAccounts" doc:name="HTTP"/>
        <logger message="Requested 'Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%input payload application/json
%output application/java
---
payload map {
        entityId: $.EntityId,
        attributes: {
                name: $.AccountName
        }
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:update-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
            <dynamics365:attributes-list ref="#[payload]"/>
        </dynamics365:update-multiple>
        <logger message="Received Response from 'Update Multiple Entities Operation'" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="DELETE_ENTITY_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/deleteAccount" doc:name="HTTP"/>
        <logger message="Requested 'Delete Entitiy Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload.EntityId]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:delete config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365"/>
        <logger message="'Delete Entity Operation' has ended with success" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="RETRIEVE_ENTITY_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccount" doc:name="HTTP"/>
        <logger message="Requested 'Retrieve Entitiy Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload.EntityId]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:retrieve config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365"/>
        <logger message="Received Response from 'Retrieve Entitiy Operation'" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="RETRIEVE_ENTITIES_BY_URL_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccountsByURL" doc:name="HTTP"/>
        <logger message="Requested 'Retrieve Multiple Operation'" level="INFO" doc:name="Logger"/>
        <dynamics365:retrieve-multiple config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" dataQueryURL="${dynamics365.resource}/api/data/v8.2/accounts?$select=name,accountnumber&amp;$top=3" doc:name="Microsoft Dynamics 365"/>
        <logger message="Received Response from 'Retrieve Multiple Operation'" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="RETRIEVE_ENTITIES_BY_QUERY_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccountsByQuery" doc:name="HTTP"/>
        <logger message="Requested 'Retrieve Multiple By Query Operation'" level="INFO" doc:name="Logger"/>
        <dynamics365:retrieve-multiple-by-query config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" query="dsql:SELECT accountid,accountnumber,name FROM account LIMIT 2" doc:name="Microsoft Dynamics 365"/>
        <logger message="Received Response from 'Retrieve Multiple By Query Operation'" level="INFO" doc:name="Logger"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="DISASSOCIATE_ENTITIES_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/disassociateEntities" doc:name="HTTP"/>
        <logger level="INFO" doc:name="Logger" message="Requested 'Dissasociate Entities Operation'"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        entityId: payload.EntityId,
        attributes: payload.EntityLinkKeys
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:disassociate config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" logicalName="account" doc:name="Microsoft Dynamics 365">
            <dynamics365:attributes ref="#[payload]"/>
        </dynamics365:disassociate>
        <logger level="INFO" doc:name="Logger" message="Finished 'Dissasociate Entities Operation' with success"/>
    </flow>
    <flow name="DO_ACTION_DEMO">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/doAction" doc:name="HTTP"/>
        <logger message="Requested 'Do Action Operation'" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
        OpportunityClose: {
                subject: payload.Subject,
                "opportunityid@odata.bind": "/opportunities(" ++ payload.OpportunityId ++ ")"
        },
        Status: payload.Status
}]]></dw:set-payload>
        </dw:transform-message>
        <dynamics365:do-action config-ref="Microsoft_Dynamics_365__OAuth_2_0_Username_Password" actionName="WinOpportunity" doc:name="Microsoft Dynamics 365"/>
        <logger message="Finished 'Do Action Operation'" level="INFO" doc:name="Logger"/>
    </flow>
</mule>