Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : ZmM0XNwDDo6bfHdY2oVj7x
Microsoft Dynamics CRM (Archived)

Connect C# console with Web Api dynamics 365 CRM online

Like (0) ShareShare
ReportReport
Posted on 10 Jul 2018 13:12:50 by 195

Hi,

    I am trying to connect console application with WebApi. Can u please guide me and don't give microsoft reference page as answers. i already tried that and nothing is happening.

*This post is locked for comments

  • Suggested answer
    Summer Garg Profile Picture
    Summer Garg 585 on 11 Sep 2020 at 06:43:16
    RE: Connect C# console with Web Api dynamics 365 CRM online

    Hi,

    Latest Way to connect C# .Net console application with D365 CRM V9.x

    crmhub.blogspot.com/.../Best-latest-way-to-connect-.net-console-application-with-D365-crm-v9.0-in-vs2019.html

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on 26 May 2020 at 10:42:06
    RE: Connect C# console with Web Api dynamics 365 CRM online

    Refer here for generic method to do CRUD operation in Dynamic CRM using C# in Web API

    https://vjcity.blogspot.com/2020/05/generic-web-api-methods-for-dynamic-crm.html

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on 11 Jul 2018 at 06:59:48
    RE: Connect C# console with Web Api dynamics 365 CRM online

    Hi Aldous,

    In order to access WebAPI in C# Console, first, you need to register the application in Azure Active Directory.

    See: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/walkthrough-register-dynamics-365-app-azure-active-directory

    You will get a client ID after this process.

    Now use the code below to get the Authorisation Token. Once you get the token, you can retrieve the required records as shown below.

    1. static string serviceUri = "yourorg.crmx.dynamics.com/";
    2. static string redirectUrl = "yourorg.api.crmx.dynamics.com/.../";
    3.  
    4. public static string GetAuthToken()
    5. {
    6.  
    7. // TODO Substitute your app registration values that can be obtained after you
    8. // register the app in Active Directory on the Microsoft Azure portal.
    9. string clientId = "3oi467rf-2336-4039-b82i-7c5b859c7be0"; // Client ID after app registration
    10. string userName = "xyz@youOrg.onmicrosoft.com";
    11. string password = "Password";
    12. UserCredential cred = new UserCredential(userName, password);
    13.  
    14. // Authenticate the registered application with Azure Active Directory.
    15. AuthenticationContext authContext = new AuthenticationContext("login.windows.net/common", false);
    16. AuthenticationResult result = authContext.AcquireToken(serviceUri, clientId, cred);
    17. return result.AccessToken;
    18. }
    19. public static void RetrieveAccounts(string authToken)
    20. {
    21. HttpClient httpClient = null;
    22. httpClient = new HttpClient();
    23. //Default Request Headers needed to be added in the HttpClient Object
    24. httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
    25. httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
    26. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    27.  
    28. //Set the Authorization header with the Access Token received specifying the Credentials
    29. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
    30.  
    31. httpClient.BaseAddress = new Uri(redirectUrl);
    32. var response = httpClient.GetAsync("accounts?$select=name").Result;
    33. if (response.IsSuccessStatusCode)
    34. {
    35. var accounts = response.Content.ReadAsStringAsync().Result;
    36. }
    37. }

    Hope this helps.

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on 10 Jul 2018 at 14:17:58
    RE: Connect C# console with Web Api dynamics 365 CRM online

    Hi,

    You can try this sample also you can use OrganizationService.SVC as an alternative. Please follow this link for sample code.

    docs.microsoft.com/.../web-api-samples-csharp

  • Suggested answer
    Nflannery Profile Picture
    Nflannery 360 on 10 Jul 2018 at 13:47:52
    RE: Connect C# console with Web Api dynamics 365 CRM online

    If it's a console app you might be better off using the SDK.

    sacconsulting.blogspot.com/.../connect-to-crm-via-console-application.html

  • Suggested answer
    PranavShroti Profile Picture
    PranavShroti 4,510 on 10 Jul 2018 at 13:25:39
    RE: Connect C# console with Web Api dynamics 365 CRM online

    please let us know what kind of code you are trying, will it be possible to share here.

    Where exactly you are stuck and what is the business scenario you are trying to address ...so that we can help you better

    I know you might have already checked this link:

    community.dynamics.com/.../programming-using-webapi-through-c-in-dynamics-crm-2016

    Regards,

    Pranav

    If found useful, please mark the answer as verified

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,379

#2
Martin Dráb Profile Picture

Martin Dráb 231,197

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading started