Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Connecting to Dynamics 365 CRM via Console App in C#

Posted on by 37

Im trying to connect to dynamics 365 via console application, using CrmServiceClient, need to input a connection string;

one of the stuff there is "RedirectUri". where do i get that from ?

Here's my Code:

static void ConnectToCrm()
{
    string connectionString = @"Authtype-OAuth;
    Username=username;
    Password=password;
    Url=https://crmurl.crm4.dynamics.com/;
    AppId= ;
    RedirectUri= ;
    LoginPrompt=never";

    crmService = new CrmServiceClient(connectionString);
    Console.WriteLine($"is ready: {crmService?.IsReady}");
    Console.Read();
}

  • RE: Connecting to Dynamics 365 CRM via Console App in C#

    ok after a few minutes of looking around i found out that the Redirect Uri is actually a connection path opening given for impersonating another admin user which i assume its the SYSTEM user that's built in... took me some time to figure that out - correct me kindly if i missed something here

  • RE: Connecting to Dynamics 365 CRM via Console App in C#

    at azure app overview i see

    Aplication (client) ID, Object ID, Directory (tenant) ID

    at Redirect URIS field there is no uri id...

    i didnt understand from where do i get this RedirectUri

    could you try to give a little more detailed direction where to look ?

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Connecting to Dynamics 365 CRM via Console App in C#

    Hi,

    You can refer to my sample code, You will need to change the username, password and organization: 

    gist.github.com/.../77f718d9a5802d4d087722d9e6a61d0a

    Docs: 

    The AppId and RedirectUri provided above are examples of working application registration values. These values work everywhere our online services are deployed. However, they are provided here as examples and you are encouraged to create your own application registration in Azure Active Directory (Azure AD) for applications running in your tenant. Use your Username, Password, and Dataverse environment URL values in the connection string along with the RedirectUri and AppId you obtain from your Azure app registration.

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation#what-should-i-do-to-fix-my-application-code-if-affected

  • Suggested answer
    RE: Connecting to Dynamics 365 CRM via Console App in C#

    Hi,

    Here you can find how to use the RedirectUri:

    Redirect URI (reply URL) restrictions - Microsoft identity platform | Microsoft Docs

    If this was helpful, please check it as verified to help others finding useful information.

    Welcome to this amazing community.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans