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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

How to make request/call to Web Services (API) from C# application?

(0) ShareShare
ReportReport
Posted on by

Hi,

We have developed Retail POS application which having inventory management. For accounting, we want to integrate with Business Central and have ultimate goal to become app partner for the same. 

I am having account of Business Central with sample data. I want to call simple Get Customer api from C# application. Do anyone have such sample application where changing credential & secrets, it will give the response. It will be easy for further POST, DELETE, PUT call.

I have searched related things but not get succeed hence writing here. Some of links are related to on-premises api call which i am not looking for. 

Thanks,

Snehal

Categories:
I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    Is this the one you are not looking for ?

    docs.microsoft.com/.../devenv-develop-connect-apps

    I just trying to understand your exact requirement.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Snehal,

    Are you looking to call web services in D365BC from a C# application and you need a sample C# code ?

    Best Regards,

  • Community Member Profile Picture
    on at

    Hi,

    Yes we want to integrate business central with our app.

    Thanks

  • Community Member Profile Picture
    on at

    Yes i need sample C# code. If you search for Azure AD integration then there will be todo app available. Likewise if having for business central it will easy to start with.

  • Community Member Profile Picture
    on at

    Hi All,

    I am able to connect api with Postman as well as Microsoft Graph Explorer. But same thing i am unabled to achieve with C# console or MVC application. So if any sample code available for the same, it will be great help for me.

    Thanks

  • jdecottignies Profile Picture
    217 on at

    Hi,

    I don't know if I correctly understood your request, but if it's just a sample of code that does the request you do with Postman, you can get a sample code (in many target language) by clikcing on the code section in postman:

    samplec_2300_2.png

    samplec_2300_2.png

  • Kannan CM Profile Picture
    5 on at

    You can try the below code to get customers list from business central and convert as xml in c#.

    I know this is bit of late reply, but would like to answer here so some one else will get benefit. :)

    string  url = String.Format("https://<<your details>>/api/v1.0/companies(<<companyid>>)/customers);

               HttpWebRequest requestObj = (HttpWebRequest)WebRequest.Create(url);

               requestObj.Method = "Get";

               requestObj.PreAuthenticate = true;

    //Basic Authentication

               requestObj.Credentials = new NetworkCredential(<<USERID>>, <<WEBACCESSKEY>>);

               HttpWebResponse responseObj = null;

               responseObj = (HttpWebResponse)requestObj.GetResponse();

               string strresult = null;

               using (Stream stream = responseObj.GetResponseStream())

               {

                   StreamReader sr = new StreamReader(stream);

                   strresult = sr.ReadToEnd();

                   sr.Close();

               }            

               //Json to XML conversion            

               XNode node = JsonConvert.DeserializeXNode(strresult, "Root");

               XmlDocument doc = new XmlDocument();

               doc.LoadXml(node.ToString());  

               //Save the document to a file.  

               doc.Save(@"C:\API\customer.xml");

  • Suggested answer
    Sohail Ahmad Profile Picture
    2 on at

    Thank You so much, You saved my day.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans