Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Microsoft Dynamics 365 Connector 2.6 Examples - Mule 4

You can better understand how to use Microsoft Dynamics 365 Connector if you build and run a demonstration project.

Before You Begin

To build and run this demo project, you need:

  • Anypoint Studio with Mule 4.0 and later.

  • Microsoft Dynamics 365 Connector v1.0.0 and later.

  • Microsoft Dynamics 365 (CRM 8.2)

Mule Flows Overview

The example that follows contains the following <flow> elements:

  • CREATE_EMPTY_CONTACT_DEMO
    Creates an empty contact entity that is required later in other flows.
    [GET] The HTTP endpoint listens to the following URL: http://localhost:8081/createContact

  • CREATE_EMPTY_OPPORTUNITY_DEMO
    Creates an empty opportunity entity that is required later in other flows.
    [GET] The HTTP endpoint listens to the following URL: http://localhost:8081/createOpportunity

  • CREATE_ACCOUNT_DEMO
    Creates an account with specified attributes and also associates the account with a contact.
    [POST] HTTP endpoint listens to the following URL: http://localhost:8081/createAccount = Request example: {"AccountName":"Test Account Name","CreditOnHold":true,"CreditLimit":1000,"ContactID":"<ID>"}

  • CREATE_MULTIPLE_ENTITIES_DEMO
    Creates multiple entities of the same type in a single batch request.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/createMultipleAccounts
    Request example: [{"AccountName":"Account Name 1","CreditOnHold":true,"CreditLimit":1500},{"AccountName":"Account Name 2","CreditOnHold":false,"CreditLimit":2000}]

  • UPDATE_MULTIPLE_ENTITIES_DEMO
    Updates multiple entities of the same type in a single batch request.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/updateMultipleAccounts
    Request example: [{"EntityId":"<ID>","AccountName":"Updated Name 1"},{"EntityId":"<ID>","AccountName":"Updated Name 2"}]

  • DELETE_ENTITY_DEMO
    Deletes an entity of a specified type.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/deleteAccount
    Request example: {"EntityId":"<ID>"}

  • RETRIEVE_ENTITY_DEMO
    Retrieves an entity of a specified type.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/retrieveAccount
    Request example: {"EntityId":"<ID>"}

  • RETRIEVE_ENTITIES_BY_URL_DEMO
    Retrieves multiple entities based on a URL request.
    [GET] The HTTP endpoint listens to the following URL: http://localhost:8081/retrieveAccountsByURL

  • RETRIEVE_ENTITIES_BY_QUERY_DEMO
    Retrieves multiple entities based on Datasense Query Language.
    [GET] The HTTP endpoint listens to the following URL: http://localhost:8081/retrieveAccountsByQuery

  • DISASSOCIATE_ENTITIES_DEMO
    Disassociates entities. You provide the ID of the entity upon which the request was made and the keys to be disassociated.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/disassociateEntities
    Request example: {"EntityId":"<ID>","EntityLinkKeys":["primarycontactid"]}

  • DO_ACTION_DEMO
    Calls the WinOpportunity action.
    [POST] The HTTP endpoint listens to the following URL: http://localhost:8081/doAction
    Request example: {"Subject":"Won Opportunity","Status":3,"OpportunityId":"<OP_ID>"}

Browse to http://localhost: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.

Test the Flows

  1. Specify your OAuth2 credentials for OAuth2 Username Password Config in /src/main/resources/mule-artifact.properties:

    • config-oauth-user-pass.username Username to initialize the session

    • config-oauth-user-pass.password Password used to authenticate the user

    • config-oauth-user-pass.resource App ID URI of the web API (secured resource). It must be the root URI, without specifing the CRM version: for example, https://<your-org>.crm2.dynamics.com/Leaving the Site.

    • config-oauth-user-pass.clientId App ID assigned to your app when you registered it with Azure Active Directory. You can find this in the Azure portal.

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

    • config-oauth-user-pass.tokenRequestEndpoint Token endpoint that is called to get the access token: for example, https://login.windows.net/<tenant-id>/oauth2/tokenLeaving the Site, where 'tenant-id' is the Azure Active Directory ID.

  2. Specify a DataSense connection timeout over 200 seconds, because the connector makes several requests to provide DataSense information.

  3. Run the project in Studio.

  4. Type localhost:8081 in your browser to access the selection menu of the demo.

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

Mule XML Flow

Update an Entity

  1. Add the Microsoft Dynamics 365 Update operation.

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

  3. Define optional attributes for the default. The entity ID is a required attribute that indicates which entity instance to update.

Example: Update Entity

Updates an account with specified attributes.

[POST] The HTTP endpoint listens to the following URL: http://localhost:8081/updateAccount

Request Example

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

Flow Definition

View on GitHub