Microsoft Dynamics 365 for Finance and Operations Connector 3.1 - Example - Mule 4
The following example illustrates how to work with the features of Anypoint Connector for Microsoft Dynamics 365 for Finance and Operations (Microsoft Dynamics 365 for Finance and Operations Connector) using the Retrieve Multiple operation to accept data and then output the results in JSON format.
This example uses the following operations in the flow:
-
HTTP Listener
Accepts data from HTTP requests -
Microsoft Dynamics 365 for Operations Retrieve multiple
Connects and executes a query to retrieve all the customer entities -
Transform Message
Outputs the results of the Retrieve Multiple operation in JSON format.
The following screenshot shows the Studio app flow for this example:
Use a properties file to define these attributes for use in the flow:
-
username="${operations.username}"
-
password="${operations.password}"
-
resource="${operations.resource}"
-
clientId="${operations.client_id}"
-
clientSecret="${operations.client_secret}"
-
tokenRequestEndpoint="${operations.request_endpoint}"
You can paste this XML code into Anypoint Studio to experiment with the flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:dynamics365ForOperations="http://www.mulesoft.org/schema/mule/dynamics365ForOperations"
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/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/dynamics365ForOperations
http://www.mulesoft.org/schema/mule/dynamics365ForOperations/current/mule-dynamics365ForOperations.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
<http:listener-connection
host="localhost"
port="8081" />
</http:listener-config>
<dynamics365ForOperations:dynamics-365-for-operations-config
name="Dynamics_365_For_Operations_Dynamics_365_for_operations"
doc:name="Dynamics 365 For Operations Dynamics 365 for operations">
<dynamics365ForOperations:oauth2-user-password-connection
username="USERNAME"
password="PASSWORD"
resource="https://muledev.sandbox.operations.dynamics.com"
clientId="CLIENT_ID"
clientSecret="CLIENT_SECRET"
tokenRequestEndpoint="https://login.windows.net/TOKEN/oauth2/token" />
</dynamics365ForOperations:dynamics-365-for-operations-config>
<dynamics365ForOperations:dynamics-365-for-operations-config
name="Dynamics_365_For_Operations_Dynamics_365_for_operations1"
doc:name="Dynamics 365 For Operations Dynamics 365 for operations">
<dynamics365ForOperations:oauth2-user-password-connection
username="${operations.username}"
password="${operations.password}"
resource="${operations.resource}"
clientId="${operations.client_id}"
clientSecret="${operations.client_secret}"
tokenRequestEndpoint="${operations.request_endpoint}" />
</dynamics365ForOperations:dynamics-365-for-operations-config>
<flow name="dynamics-op-testFlow">
<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/retrieve" />
<dynamics365ForOperations:retrieve-multiple doc:name="Retrieve multiple"
config-ref="Dynamics_365_For_Operations_Dynamics_365_for_operations1">
<dynamics365ForOperations:data-query-url ><![CDATA[https://muledev.sandbox.operations.dynamics.com/data/Customers]]></dynamics365ForOperations:data-query-url>
</dynamics365ForOperations:retrieve-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>
</mule>