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 187

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

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: How to Retrieve Account data using Web Api in console application

    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);
    }

    }
    }
    }

  • Balaji Karpurapu Profile Picture
    Balaji Karpurapu 187 on at
    RE: How to Retrieve Account data using Web Api in console application

    Hi Goutam Das

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

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: How to Retrieve Account data using Web Api in console application

    Hi,

    Please check below reference-

    rajeevpentyala.com/.../

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to Retrieve Account data using Web Api in console application

    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.

  • Balaji Karpurapu Profile Picture
    Balaji Karpurapu 187 on at
    RE: How to Retrieve Account data using Web Api in console application

    Hi Adrian Begovich,

    thank you for response.

    I want to use WebApi url not organization url

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 1,019 Super User 2025 Season 1 on at
    RE: How to Retrieve Account data using Web Api in console application

    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.

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,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans