************************************************************
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 *
************************************************************************
Microsoft Dynamics 365 Connector
Select
Version: 1.0.0
The Microsoft Dynamics 365 Connector enables integration with Microsoft Dynamics 365 Customer Relationship Management (CRM) Web API.
Release Notes: Microsoft Dynamics 365 Connector Release Notes
Sample: ms-dynamics-365-demo.zip
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.
Before You Begin
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
-
Download and install Java 8 (latest version) or Java 7 (deprecated by Oracle).
-
Click the Anypoint Exchange 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
-
In Anypoint Studio, click File > New > Mule Project.
-
Specify a Project Name and click Finish.
-
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.
-
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.
-
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.
-
Click the green plus sign to the right of Connector Configuration.
-
Provide the Client ID and Secret values.
-
Choose an action if a token is not provided:
-
EXCEPTION (Default) - Causes an exception if there is no token.
-
STOP_FLOW - Stops running the Mule project if there is no token.
-
-
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
-
Click the green plus sign to the right of Connector Configuration.
-
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.
-
-
Click Test Connection to ensure that your credentials are accepted at the server endpoint.
-
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
-
In Package Explorer, right click your project’s name, and click Run As > Mule Application.
-
Check the console to see when the application starts. You should see messages such as these if no errors occur:
To Configure Connector Operations
To Authorize Access to the Dynamics 365 Server
-
Set Operation to Authorize (OAuth 2.0 Connection only].
-
Leave the value for the State field empty, it is handled internally by Mule.
-
Provide the Access Token URL given to you by the service provider.
-
Provide the endpoint (required) that issues the token: Example:
https://login.windows.net/TENANT/oauth2/token
, where TENANT is the Azure Active Directory ID. -
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. -
Provide the access token ID (required) - The ID of the access token that’s used to identify the call
-
Specify the Scope (required) - For OpenID Connect, the scope must include the openid, which translates to login permission in the consent UI.
-
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
. -
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
-
Set Operation to Unauthorize (OAuth 2.0 Connection only).
-
Provide the Access Token URL that you used to authorize access to the Microsoft Dynamics 365 server.
To Create an Entity
-
Set Operation to Create.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
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
-
Set Operation to Create Multiple.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
Click Use Single Transaction to indicate that if the transaction fails, the transaction is rolled back.
-
Click to add a MEL expression for the Logical Name attribute.
-
Define optional attributes from a MEL expression, or manually set attributes as one or more key and value Map pairs.
To Delete an Entity
-
Set Operation to Delete.
-
Specify a MEL expression for the ID field.
-
Specify a logical name (required).
To Delete Multiple Entities
-
Set Operation to Delete Multiple.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
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
-
Set Operation to Disassociate.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
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
-
Set Operation to Do Action.
-
Specify the Action Name (required).
-
Specify the Bounded Entity ID.
-
Specify the Bounded Entity Type.
-
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
-
Set Operation to Invoke.
-
Specify a URI or MEL expression for the Web API.
-
Specify an HTTP method (required): DELETE, GET, PATCH, POST, or PUT.
-
Specify the request HTTP Headers from the expression or manually.
-
Specify the JSON string value (required) that is placed in the body of the request.
To Retrieve an Entity
-
Set Operation to Retrieve.
-
Specify a MEL expression for the ID field.
-
Specify a Logical Name (required).
To Retrieve Multiple Entities
-
Set Operation to Retrieve Multiple.
-
Specify the Data Query URL or MEL expression for what to retrieve.
-
Specify the Paging Fetch Size in pages to retrieve. The default is 100 pages.
To Retrieve Multiple Entities by Query
-
Set Operation to Retrieve Multiple By Query.
-
Specify the query language.
-
Configure the Query for what you want to retrieve. For more information on DataSense queries, see DataSense Query Language.
-
Specify the Paging Fetch Size in pages to retrieve. The default is 100 pages.
To Update an Entity
-
Set Operation to Update.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
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
-
Set Operation to Update Multiple.
-
Specify the Logical Name (required), which is the name of the schema in lowercase.
-
Click Use Single Transaction to indicate that if the transaction fails it is rolled back.
-
Click to add a MEL expression for the Logical Name attribute.
-
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
-
Import the demo project into your workspace using Anypoint Exchange or using the Import command in the File menu.
-
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.
-
-
Specify DataSense Connection Timeout with more than 200 seconds because the connector makes several requests to provide DataSense information.
-
Run the project in Studio.
-
Type
0.0.0.0:8081
in your browser to access the selection menu of the demo. -
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.
<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
<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
<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:
{"AccountName":"Test Account Name","CreditOnHold":true,
"CreditLimit":1000,"ContactID":"CONTACT_ID"}`
<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:
[{"AccountName":"Account Name 1","CreditOnHold":true,"CreditLimit":1500},
{"AccountName":"Account Name 2","CreditOnHold":false,"CreditLimit":2000}]
<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}
<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:
[{"EntityId":"ENTRY_ID","AccountName":"Updated Name 1"},
{"EntityId":"ENTRY_ID","AccountName":"Updated Name 2"}]
<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"}
<flow name="DELETE_ENTITY_DEMO">
<http:listener config-ref="HTTP_Listener_Configuration" path="/deleteAccount" doc:name="HTTP"/>
<logger message="Requested 'Delete Entity 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"}
<flow name="RETRIEVE_ENTITY_DEMO">
<http:listener config-ref="HTTP_Listener_Configuration" path="/retrieveAccount" doc:name="HTTP"/>
<logger message="Requested 'Retrieve Entity 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 Entity 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
<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&$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
<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
Disassociates entities. Provide the ID of the entity upon which the request was made and the keys to disassociate.
POST - The HTTP endpoint listens at: http://0.0.0.0:8081/disassociateEntities
Request example:
{"EntityId":"ENTRY_ID","EntityLinkKeys":["primarycontactid"]}
<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 'Disassociate 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 'Disassociate 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"}
<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
<?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 Entity 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 Entity 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 Entity 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&$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 'Disassociate 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 'Disassociate 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>