• Bli partner
  • Pålogging
  • Norge
    • Global
    • Belgique - Français
    • België - Nederlands
    • Danmark
    • Deutschland
    • España
    • France
    • Italia
    • Nederland
    • Österreich
    • Polska
    • Schweiz
    • Sverige
    • United Kingdom
  • Global Global Global en
  • Belgique - Français Belgique - Français Belgique - Français fr-be
  • België - Nederlands België - Nederlands België - Nederlands be
  • Danmark Danmark Danmark da
  • Deutschland Deutschland Deutschland de
  • España España España es
  • France France France fr
  • Italia Italia Italia it
  • Nederland Nederland Nederland nl
  • Norge Norge Norge no
  • Österreich Österreich Österreich at
  • Polska Polska Polska pl
  • Schweiz Schweiz Schweiz ch
  • Sverige Sverige Sverige sv
  • United Kingdom United Kingdom United Kingdom en-uk
QBS group
Menu
  • Informasjonssenter
    • Blogg
    • Arrangementskalender 2021
    • Arrangementer
    • Nyheter
    • Referanser
    • Treninger
    • Close
  • Løsninger
  • Tjenester
    • Ready to Go for Dynamics 365 Business Central
    • Ready to Start Dynamics 365 Customer Engagement
    • Take the Lead
    • Oppgraderingstjenester
    • QBS Academy
    • QBS Azure Services
    • Close
  • Program
    • Bli partner
    • Indirect CSP
    • ISV Program
    • Våre partnere
    • Close
  • Om oss
  • Kontakt
Bloggen er skrevet av:
Tid for å lese:n.v.t.
Del dette:
  • Del med Facebook
  • Del med Twitter
  • Share on Google+
  • Del med Linkedin
  • Del med epost
22 mars 2021

How to use the Dynamics 365 Business Central API with C# in Service-to-Service scenarios

Du er her: Hjem » How to use the Dynamics 365 Business Central API with C# in Service-to-Service...

Business Central

Dynamics 365

Tech

A question that was raised more frequently than others lately is, how to use the Business Central API from C# in Service-to-Service scenarios?

Within the Business Central community, C# is the most frequently used language to code Azure Functions and Windows Services using DotNET core.

There are a few choices to make when deciding how to design your code and we’ll discuss the most important ones being security and structure of your classes.

Security

When you connect to Business Central using the API you have two choices. OAuth with tokens or Basic with a Web Service Access Key.

Using OAuth is the preferred solution which is promoted by Microsoft. The problem is that OAuth is only supported when the software calling into Business Central has the ability to provide a user interface.

This user interface is required to show a window to login and return the access token.

Business Central currently does not support OAuth in service-to-service scenarios except for the API that is handling the service tier itself.

That leaves you with the choice of going back to Basic authentication with a Web Service Access Key or to use Azure as the middle man.

Most examples that you can find online of authentication use the latter option and therefor this blog is about the other option that is hard to find information on.

Simplicity is the core value of Business Central and even though customers using Business Central have an Office 365 tenant, not everyone has their Azure tenant configured.

Using Azure as the middle man for security may be the easy way out for a developer, it requires each user of your solution to set this up in their Azure tenant.

The advice is to use Basic Authentication for Service-to-Service connections until Microsoft is finished with a final solution for OAuth in these scenarios.

Classes

There are two options when you design your solution to structure your classes. You can have them generated based on the metadata of the API endpoint or you can design your own classes.

Both options have pros and cons and the most important reason why the example repository creates its own classes is again simplicity and to explain clearly how the API works rather than working through a pile of generated code that will leave 95% unused.

In real life implementations, many developers will choose to generate the classes based on the endpoint, especially if the API has strong versioning like the one provided by Microsoft.

A strong exception would be if you only need a few API methods implemented or if the API is a custom API for a project and subject to change.

If changes to the API happen on a frequent basis, which is not recommended but happens often in real-life scenarios, you can be more flexible in your error handling if you define your classes yourself.

Rest Client

To send data back and forth your code needs a Rest Client and, in the example, we use the one from RestSharp. This is a very popular NuGet package. Another frequently used Rest Client is the Simple Client (Simple.OData.Client) which is also available as NuGet package.

Json Handling

Json is not native to C#. It was created for JavaScript and in order to use it in C# you can use either NewtonSoft or the new System.Text.Json from Microsoft. Both are created by the same person who works for Microsoft now.

You will most likely find out that both libraries have scenarios where they work and fail.

NewtonSoft Linq supports the use of JArray and JObject in a similar way as AL has the native JsonArray and JsonObject although you will find the NuGet libraries much more flexible and powerful.

Value

Each result that you get from Business Central has a wrapper with a tag called [Value]. In almost all cases you won’t need this in your code. The function ConvertToDataSet converts the result of an API call into a Json Array without the [Value] wrapper.

The API Endpoint

When Business Central is hosted by Microsoft the API endpoint has up to 6 variables that determine things like the Sandbox you are using (if any), the Tenant ID (obsoleted by OAuth) and the details about the API version, and group.

Learning more

To work effectively with the Business Central API it is important to have in-depth knowledge of Json and Rest. QBS Group offers a dedicated workshop to gain this knowledge.

Resources

Link to Github: https://github.com/qbsgroup/QBS.API.Example
https://www.kauffmann.nl/2021/01/07/deprecation-of-basic-auth-for-saas-has-been-postponed-to-2022/
https://www.kauffmann.nl/2020/09/14/service-to-service-authentication-for-automation-apis-in-business-central/
https://www.youtube.com/watch?v=dp_mzqzNvPA&t=1553s

Flere artikler

Kanskje er dette også noe for deg

  • Do you really need the Business Central Universal Code Initiative? Are you shocked? Let’s hope not…

    What’s the Business Central Universal Code Initiative? For a […]

  • Directions EMEA in Milan and we as QBS Group will be there!

    It was a tough year without meeting each other […]

  • Dynamics 365 Update Webcast 1 July 2021

    This series of webcasts is intended to share the […]

  • Cosmos versus Azure SQL and how to integrate with Dynamics 365 Business Central #MSDYN365BC

    One of the highest-scoring FAQs from partners and customers […]

  • Dynamics 365 Update Webcast 27 May 2021

    This series of webcasts is intended to share the […]

  • HELP! My Application Insights EXPLODES!

    At QBS Group we are promoting the use of […]

  • From Dynamics 365 Business Central to Business Applications

    How do I move from Dynamics 365 Business Central […]

  • ERP Migration – the Friendly Hill That One Day May Become a Hostile Mountain

    Cloud computing is probably the most profound IT-innovation of […]

  • Dynamics 365 CRM Update Webcast 11 May 2020

    Get the latest insights from Microsoft Dynamics 365 CRM […]

  • Update on Dynamics 365 Business Central 27 August 2019

    This series of webinars is intended to share the […]

  • New Pricing for Dynamics 365 Customer Engagement & Unified Operations per the 1st of October 2019

    Microsoft announces new Pricing for Dynamics 365 Customer Engagement […]

  • Update on Dynamics 365 Business Central 13 June 2019

    This series of webinars is intended to share the […]

  • Newsletter
  • Update on Dynamics 365 Business Central 9 May 2019

    Watch here the Webinar update of the 9th of May 2019.

  • Update on Dynamics 365 Business Central 11 April 2019

    This series of webinars is intended to share the […]

  • Update on Dynamics 365 Business Central 14 March 2019

    Technical update and License update 1 April 2109

  • White Paper – Microsoft Dynamics 365 the perfect platform for digital transformation in the mid-market

    At QBS group we’re all about Dynamics partners – […]

  • Arrangementskalender 2021
  • Update on Dynamics 365 Business Central 7 February 2019

    This series of webinars is intended to share the […]

  • Ready to Start Microsoft Dynamics 365 Customer Engagement
  • Directions EMEA 2018 Business Report

    This unique report features a broad but insightful and independent business reporting on the happenings at DIRECTIONS EMEA 2018.

  • Microsoft Dynamics 365 – the perfect platform for new business ventures

    Microsoft has thousands of business partners. Is this market not the red ocean?

  • Ready to Go for Dynamics 365 Business Central
  • Ready to Start Microsoft Dynamics 365 Customer Engagement program – Reference MKB365

    MKB365 has set up a separate business model for […]

  • Highlights from eXtreme 365 EMEA 2018

    Get all the highlights of eXtreme 365 EMEA 2018 and watch this 6 minutes video.

  • What can Dynamics CRM Partners expect from eXtreme365 EMEA 2018?

    eXtreme 365 is the annual event for Microsoft Dynamics […]

  • The evolution of Dynamics 365 opens the door for new opportunities

    Being a Dynamics CRM partner today is like dancing on a volcano – far from boring!

  • “Ever change a winning team”

    “Ever change a winning team” Alex Ferguson, former football […]

  • What’s new NAV 2018

    Understanding these new possibilities is crucial for your product and / or marketing plans.

  • GDPR … and what now ?

    Starting from 25 May 2018 there is going to be a […]

  • Position NAV as stepping stone for more Dynamics 365 ‘Tenerife’ deals

    Since the introduction of the Dynamics 365 Business Edition in the US and Canada late 2016, the position of Dynamics NAV is under pressure! Competitors took the chance to position NAV as an old-fashioned solution and that’s a direct threat to your NAV business!

  • Exclusive interview with Jeff Edwards Director for ERP Channel Strategy Microsoft

    “If you’re an ERP partner not selling CRM, and not having a focus on verticals in 2018 – I don’t know what you’re doing”

  • QBS Azure Services
  • Oppgraderingstjenester
  • Dynamics 365 Acceleration Program
  • ISV Program

    Som ISV er det første fokuset ditt å utvikle […]

  • Indirect CSP

    Som Microsoft-partner overveier du kanskje å inngå samarbeid med […]

  • DIRECTIONS EMEA 2017 business report is available now!

    Never before it was so important for Dynamics partners […]

  • Business Edition is off – long live Tenerife!

    Our team is just getting back from Directions in […]

  • QBS Academy
  • Directions EMEA 2017 Madrid

    Find here all the information you as Microsoft Reseller […]

  • Reflections on this weeks announcements from Microsoft

    One of our founders summarized this week plain and […]

  • The CSP Direct model is like an iceberg

    We noticed that the market is changing, our clients are, more and more, requesting a subscription based approach. This allows them to not have their own services nor the hassle.

  • General Data Protection Regulations (GDPR) – a Microsoft perspective

    The EU General Data Protection Regulation (GDPR) is the […]

  • Inspire 2017 – A look back at 11 big stories for Microsoft Dynamics Partners

    As a longtime WPC / Inspire-observer with a perspective […]

  • Part 4 Microsoft Dynamics Development Preview

    Microsoft released during last Christmas an Azure Virtual Machine […]

  • What Dynamics Partners can expect from Inspire 2017

    Microsoft is on the move! Ever since the start […]

  • 7 Strong arguments to sell Dynamics NAV today

    Dynamics NAV finds itself in an interesting position today! […]

  • Dynamics NAV Development: Extensions or Extinction?

    No one wants to be a dinosaur, it does […]

  • Do you know your new competitors with Dynamics 365 for Financials?

    The new kids-on-the-block with outsell you on Dynamics 365 […]

  • What is the Microsoft Cloud Solution Provider Program (Microsoft CSP)

    The Microsoft Cloud Solution Provider Program (CSP) enables partners to directly manage their entire Microsoft cloud customer lifecycle.

  • Dynamics 365 Business Edition: Opportunity or Threat

    Microsoft will be launching Dynamics 365 Business Edition in […]

  • Get yourself a niche, in order to be successful

    At QBS group we believe that our partners deserve […]

  • After Directions EMEA 2016, Microsoft Dynamics NAV partners face crucial decisions on their future

    As a longtime Microsoft-observer with a perspective geared toward […]

  • What is the Microsoft CSP Program?

    In order to be successful in a Cloud first, […]

Det sier andre om QBS group

  • Ferry Schrijnewerkers

    Owner en Co-founder at MKB365

    Since the start of our company 4 months ago, we have already completed 12 Dynamics 365 for Sales implementations.

    Read the reference case
  • Joaquim Antón Gimeno

    GRUPO CHOICE

    "Our relationship with QBS group allows us to improve our marketing strategy."

    Read the reference case
  • Sofkia

    "Our alliance with QBS group has been very important in the development of our business strategy."

    Read the reference case
  • VS Sistemas

    "QBS group helps us build our road to success."

    Read the reference case
  • Berith Skov - C2IT Business Solutions

    “We are very satisfied with the services provided by and through QBS group."

    Read the reference case
  • Herke ICT Group- Karing Buzing

    We are once again part of a NAV community.

    Read the reference case
  • Owe Loonstra - Verito

    Manager Sales & Marketing

    The fact that we belong to a larger organisation gives our customers security.

    Read the reference case
  • Adfocom - Jeroen Kersten

    Partner Care saved us a lot of time.

    Read the reference case
  • NavAzure - Michael Francois Knudsen

    “It is important to me, that I through QBS become part of a greater network, where partners can share experience"

    Read the reference case
  • Blisss - Dirko Wijers

    Without the help from QBS group we wouldn’t have succeeded.

    Read the reference case

Program

  • Bli partner
  • Indirect CSP
  • ISV Program
  • Våre Partners

Informajonssenter

  • References
  • Blogg
  • Training
  • Arrangementer
  • Nyheter
  • Nyhetsbrev

Tjenester

  • QBS Azure Services
  • Oppgraderingstjenester
  • QBS Academy

Follow QBS group

© Copyright QBS group 2023
  • Cookie Policy
  • Privacy Policy
ERP Migration – the Friendly Hill That One Day May Become a Hostile ... From Dynamics 365 Business Central to Business Applications
Please complete the form

Contact us, please complete this form

Join QBS Group, please complete this form

Join QBS Group please complete the form

Sign up QBS Group Membership

Send me an email.
Please complete the form


If you are not seeing the form, please check your ad-blocker settings.

Download Center

Please complete the form

Register for this event
QBS
  • Norge
    • Global
    • Belgique - Français
    • België - Nederlands
    • Danmark
    • Deutschland
    • España
    • France
    • Italia
    • Nederland
    • Österreich
    • Polska
    • Schweiz
    • Sverige
    • United Kingdom
  • Informasjonssenter
    • Blogg
    • Arrangementskalender 2021
    • Arrangementer
    • Nyheter
    • Referanser
    • Treninger
    • Back
  • Løsninger
  • Tjenester
    • Ready to Go for Dynamics 365 Business Central
    • Ready to Start Dynamics 365 Customer Engagement
    • Take the Lead
    • Oppgraderingstjenester
    • QBS Academy
    • QBS Azure Services
    • Back
  • Program
    • Bli partner
    • Indirect CSP
    • ISV Program
    • Våre partnere
    • Back
  • Om oss
  • Kontakt

This website uses Cookies to give you the best experience. Agreed by clicking the 'Accept' button. After you've clicked on "Accept" you accept QBS group Privacy Statement.

Scroll to top