×

    By submitting this form, you are agreeing to Folio3's Privacy Policy and Terms of Service.

    Get a free Consultation

     Introduction

    Dynamics 365 Business Central is a comprehensive enterprise resource planning (ERP) software solution for mid-sized businesses that is quick to set up, simple to use, and easy to adjust. Innovations in product design, development, implementation, and usability have always been guided by simplicity.

    Business Central & API Services

    There are three ways to implement the API in the Business Central. Focus here is to discuss OData Web Service & OData Web service.

    • SOAP
    • REST API
    • OData Web Service

    SOAP

    SOAP is widely used to integrate the third party system in BC for so long but business central will   obsolete the implementation of SOAP service in later version. For now, the date is not decided to dismantle the SOAP.

    REST API

    REST stands for representational state transfer and widely used in the industry.  The business central also using the REST architecture to communicate with the third party systems.  There are numerous built-in APIs in Business Central, all of which can be used without writing any code and with very little setup. The default end points of API format is mention in below table.

    Means of connection Common endpoint service
    Usage Production
    Endpoint https://api.businesscentral.dynamics.com/v2.0/<environment name>/api/v2.0
    Example:
    https://api.businesscentral.dynamics.com/v2.0//production/api/v2.0

     

    For sandbox, we adjust the link and use sandbox in the link. Like https://api.businesscentral.dynamics.com/v2.0/cronus.com/sandbox/api/v2.0

    Business central supports multiple environments at a time.

    Here is the example of get all the companies through built-in rest endpoints.
    The HTTP request to get the companies.
    https://{businesscentralPrefix}/api/v2.0/companies

    The response of the request is given below.

    {
    "id": "id-value",
    "systemVersion": "17806",
    "name": "CRONUS US",
    "displayName": "CRONUS USA, Inc.",
    "businessProfileId": "",
    "systemCreatedAt": "2017-01-23T00:24:31.766Z",
    "systemCreatedBy": "f2a5738a-44e3-ea11-bb43-000d3a2feca1",
    "systemModifiedAt": "2020-08-21T00:24:31.777Z",
    "systemModifiedBy": "f2a5738a-44e3-ea11-bb43-000d3a2feca1"
    }

    OData Web Service

    Open data protocol outlines a group of ideal techniques for creating and using RESTful APIs. When creating RESTful APIs, OData frees you up to concentrate on your business logic rather than worrying about how to define request and response headers, status codes, HTTP methods, URL conventions, media types, payload formats, query parameters, etc. OData also offers instructions for keeping track of changes, specifying actions for reusable procedures, and submitting batch or asynchronous requests.

    How we enable OData Services 

    You can use OData services by enabling OData service for Business Central and also modify URL and ports for ODataServices.

    As Soap is depreciating for the replacement, we have OData as options in Business Central and we can create API pages with some configuration. You can set the below configuration as per requirements.

    Here Page Type is equal to API, which configure Page as API there are other configuration as well including api version, publisher and group and also includes OData fields to follow OData standard.

    The following is the sample URL to call OData API 

    {baseurl}/ODataV4/Company(‘CRONUS%20USA%2C%20Inc.’)/pageName(OptionalParameter)

    Querying & Filtering

     As OData is easily filtering and querying the tabular data. Business Central also supports the filtration and other major feature of OData like $top, $count, e.t.c.
    {baseurl}/ODataV4/Company(‘CRONUS%20USA%2C%20Inc.’)/pageName(OptionalParameter)?$filter = companyname eq ‘test’
    So the filter paramter is added in the URL and you filter the data as per the requirements with the multiple columns

    Conversion of  CodeUnit As OData

    CodeUnit used in Business Central to define the logic we can also convert codeunit to OData Mehtod just to adjust our link. Microsoft call this Codeunit as unbound function.

    One typical application for Business Central SOAP endpoints is to expose an AL method so that it can be called as a web service. By utilising OData V4 unbound actions as explained in this article, the same result can be obtained.
    Therefore, you can use codeunit as OData with below URL adjustment

    {baseurl}/ODataV4/{serviceName}_{procedureName}?company={companyName|companyId}

    By adding method name with underscore, you can use the code unit. 

    Limitations of OData

    Filters
    Exception occurs when you will use the same field with OR operator.
    Lambda operators
    Lambda operation is not supported by Business Central OData API’s 

    Deep insert and patching

    On API page types, Business Central allows deep insert. On sites exposed as ODataV4 web services, it is not supported. Although ODataV4 online services might be usable in some circumstances, they are not advised. Business Central does not support deep patching. Patching nested entities will require submitting multiple requests.

    Conclusions
    Web services is an important and backbone of any ERP. Business central used varieties of approaches including OData, API and SOAP. Soap will depreciating soon and most of the companies will move forward to OData or Custom API solution. While selecting the Approach companies should understand their need. OData is recommended and for some cases, Custom API is the solution. However, there are some limitation of OData which major includes deep insert. You can use unbound function there as well.

    Usman Asif is working at folio3 in the capacity of Senior Software Engineer. He is a part of dynamics department. He is currently managing the COMAX product with the business central and working with different clients and with different E-Commerce domains.