Wednesday, March 30, 2016

Web API for Microsoft Dynamics CRM Online or internet facing deployments

What is Web API?
Web API is implementation of OData (Open Data Protocol) which is an OASIS standard that defines the best practice for building for building and consuming RESTful APIs.
Web API Authentication
- Javascript Web Resources: You don't need to specify authentication pattern if call is made from the CRM application.
- CRM On-Premise: When you use the Web API for on-premises deployments you must include the user’s network credentials.
- CRM Online or IFD: When you use the Web API for CRM Online or an on-premises Internet-facing deployment (IFD) you must use OAuth.

Steps to register your IFD or CUSTOM CRM application in Azure Active Directory 
Step 1: Login to Windows Azure portal
Step 2: Select your organization and click on applications

It will list down all the application configured in selected organization.


Step 3: To Add your CRM application click on Add button.

Step 4: Add an application my organization is developing
Step 5: Enter name of your application


*Note: Web application or WEB API is selected for web application and for desktop, console it should be native client application. Since our sample is native client application, hence selected “Native” option
Step 6: Click Next and add redirect URI

Step 7: Once application is added, we need to configure it

Step 8: Add Microsoft dynamics crm permission to this application

Step 9: Assign Delegate Permission to Microsoft Dynamics CRM


Step 10: Save the Changes

Step 11: Copy Client ID, that we will use in native client application

Console Application: This sample demonstration will use OAuth authentication to connect CRM Services and your application MyCRM registered in Azure active directory.


static void Main(string[] args)
            // TODO Substitute your correct CRM root service address,
            string resource = "";

            // TODO Substitute your app registration values that can be obtained after you
            // register the app in Active Directory on the Microsoft Azure portal.
            string clientId = "db329e3d-4d6d-4ef2-9195-bfad1daed689";
            string redirectUrl = "";

            // Authenticate the registered application with Azure Active Directory.
            AuthenticationContext authContext =
                new AuthenticationContext("", false);
            AuthenticationResult result = authContext.AcquireToken(resource, clientId, new

        static async Task RunAsync(AuthenticationResult result)
            using (var client = new HttpClient())
                client.BaseAddress = new Uri("");
                client.Timeout = new TimeSpan(0, 2, 0);  // 2 minutes
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", result.AccessToken);
                HttpResponseMessage response = await client.GetAsync("api/data/v8.0/accounts");

                if (response.IsSuccessStatusCode)
                    string s = await response.Content.ReadAsStringAsync();



Make sure to add nuGet package “Active Directory Authentication Library” in your project.

: Since we have not passed credentials in code, login window opens, here enter your credentials.

Once you sign-in JSON response will be returned.


Helpful Links:


  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in MICROSOFT DYNAMICS CRM kindly contact us
    MaxMunus Offer World Class Virtual Instructor led training on MICROSOFT DYNAMICS CRM We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Saurabh Srivastava
    Skype id: saurabhmaxmunus
    Ph:+91 8553576305 / 080 - 41103383

  2. Hi I have developed as is and is working fine in local but when deployed in azure it doesn't work, how do we pass credentials

  3. Great! This is really informative blog about Crm Microsoft. Your blog is really good.

  4. Amazing information that you have shared with us, your blog is really full of knowledge about business analyst. This amazingly help me to understand Microsoft CRM consultant skills. Thank you so much for sharing this with us.

  5. Great! This is really informative blog about Crm Microsoft. Your blog is really good.

    customized crm solution

  6. "Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it.
    This paragraph gives clear idea for the new viewers of blogging, Thanks you. You’re doing a great job Man, Keep it up.
    Seo training
    Seo training in dhaka
    SEO Services in bangladesh

  7. I always like and such a super contents of these post, Good info I gained more information about that. Thanks for such a helpful information. Keep it up.
    CRM Software in Dubai
    CRM Software
    CRM Software in UAE
    Best CRM Software
    Customer Relationship Management Software

  8. I always curious to know more about how we can enhance our skill, how we can improve our portfolio to add some attractive certificate. I got some valuable points through this blog.
    best crm software