How to connect Dynamics CRM 2016 instance running on Azure Cloud through Java?

  • I want to integrate my java application with Dynamics CRM.

  • for that i need to Develop Java method to connect Dynamics CRM 2016 instance running on Azure Cloud, and authenticate the calling request from Java.

  • I want to Create Lead record with lead entity fields including option sets fields. New Lead record will be mapped to a default CRM user/service account configured for integration purpose.

  • Any sample code for connecting to REST endpoint will be helpful.

2 answers

  • answered 2019-11-14 08:27 AnkUser

    You can do so. Dynamics have exposed REST API for use and this API is no different than any.

    Here you can find all the details about API.

    I just googled and found this nice article of connecting to Dynamics crm (online) via REST

  • answered 2019-11-14 09:34 Mohit Verma

    As rightly suggested by @ankuser, there are lot of resouces available to query through Dynamics CRM api. Important point to remember that Microsoft offer ADAL Azure Active Directory Authentication Library for Java to help you with the bearer token.

    Bearer token you would be needing it to call dynamics api:

    Here is sample code to get the token:

    private final static String CLIENT_ID = "00000000-0000-0000-0000-000000000000";
    //CRM URL
    private final static String RESOURCE = "https://org.crm.dynamics.com";
    //O365 credentials for authentication w/o login prompt
    private final static String USERNAME = "administrator@org.onmicrosoft.com";
    private final static String PASSWORD = "password";
    //Azure Directory OAUTH 2.0 AUTHORIZATION ENDPOINT
    private final static String AUTHORITY = 
        "https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000";
    
    AuthenticationContext context = null;
    AuthenticationResult result = null;
    ExecutorService service = null;
    try {
        service = Executors.newFixedThreadPool(1);
        context = new AuthenticationContext(AUTHORITY, false, service);
        Future<AuthenticationResult> future = context.acquireToken(RESOURCE,
                CLIENT_ID,
                USERNAME,
                PASSWORD, null);
        result = future.get();
    } finally {
        service.shutdown();
    }
    
    String token = result.getAccessToken();
    

    Additional reference , you can browse through below code repo:

    https://github.com/jlattimer/CrmWebApiJava

    For the detailed step to step guide , please refer :

    https://www.fmtconsultants.com/connect-java-application-crm-simple-java-console-application/

    Hope it helps.