web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

.net core app connects with dynamics 365 online

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I am trying to consume the dynamics 365 online web api call through the .net application, here is the sample code, but it says unauthorized. Please help

 

HttpResponseMessage response = new HttpResponseMessage();
            string requestUrl = string.Empty;
            applicationModel result = null;

            var httpClientHandler = new HttpClientHandler()
            {
                Credentials = new NetworkCredential(_config.GetValue("OnlineServiceSettings:UserName"),
                _config.GetValue("OnlineServiceSettings:Password"), _config.GetValue("OnlineServiceSettings:Domain"))
            };
            HttpClient _httpClient = new HttpClient(httpClientHandler);
            requestUrl = $"https://webensight.api.crm3.dynamics.com/api/data/v9.1/accounts";
            response = await _httpClient.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                //string result = response.Content.ReadAsStringAsync().Result;
                result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
                return result;
            }

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    You will need to follow this docs.microsoft.com/.../authenticate-oauth . You will need to create an app registration in Azure AD and use that to connect to the API.

    Omar

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Please add security protocol mentioned in below, before your HTTPRequest and HTTPResponse:

    ServicePointManager.Expect100Continue = true;

                   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

                          | SecurityProtocolType.Tls11

                          | SecurityProtocolType.Tls12

                          | SecurityProtocolType.Ssl3;

    Its working for me

  • sdnd2000 Profile Picture
    2,510 on at

    so every app got to be registered with azure AD?

  • sdnd2000 Profile Picture
    2,510 on at

    it didn't work.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 96

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 69 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans