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 :
Microsoft Dynamics CRM (Archived)

How to Retrieve Account data using Web Api in console application

(0) ShareShare
ReportReport
Posted on by 193

I have requirement to retrieve account records by using webapi filter condition (Filter condition should have more than one value).

Can you please help me on how to connect CRM from console application using WebApi. Please share any sample working code

Thanks 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Balaji Karpurapu,

    Start by connecting to your Dynamics CRM instance using a C# Console Application. You will be able to retrieve data from the Account entity once you have connected to your instance. This article explains how to achieve this.

  • Balaji Karpurapu Profile Picture
    193 on at

    Hi Adrian Begovich,

    thank you for response.

    I want to use WebApi url not organization url

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Please refer below samples from documentation. As suggested above, you first need to authenticate and then query data. The documentation has some other basic concepts as well.

    docs.microsoft.com/.../query-data-csharp

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Please check below reference-

    rajeevpentyala.com/.../

  • Balaji Karpurapu Profile Picture
    193 on at

    Hi Goutam Das

    thank you for response, We are using On-Premise environment

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Balaji , 

    Below code is working for me , try with this -


    using System;
    using System.Net;
    using System.Net.Http;

    namespace CRMConnectionTestProject
    {
    class WebAPI
    {
    static void Main(string[] args)
    {
    string _userName = "goutam"; // Replace User Name
    string _passWord = "*****"; //Replace password
    string _domain = "*****"; // Replace domain name
    HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential(_userName, _passWord, _domain) });
    client.BaseAddress = new Uri("http://XXX.XX.XX.X/TEST" );  // Put organization URL here
    client.Timeout = new TimeSpan(0, 2, 0);
    HttpRequestMessage request = null;
    try
    {

    //Here you need to put web api URL
    request = new HttpRequestMessage(HttpMethod.Get, new Uri("http: // XXX.XX.XX.X/.../accounts?$select=name "); 
    var response = client.SendAsync(request, HttpCompletionOption.ResponseContentRead).Result;
    if (response.IsSuccessStatusCode)
    {
    var accountInfoJson = response.Content.ReadAsStringAsync(); // You will get the JSON result here


    }
    else
    {
    throw new Exception("An error occured.");
    }
    }
    catch (Exception err)
    {
    throw new Exception(err.Message);
    }

    }
    }
    }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans