Skip to main content

#msdyn365bc - How Do I Develop a Custom API Page?

Hi Readers,

As discussed in last article we will start develop API Page for integration from #msdyn365bc or #MSDynNAV.

If you want to see other articles in this series please refer here.

API Pages are for integration purpose and cannot be used in the client for users access. There are specific rules need to be followed during development of API Pages.

Update 16/09/2023 - 

Now available for Business Central: Suite Engine's API Engine

Suite Engine's API Engine is a robust tool developers can use to build integrations from within Business Central to any number of external sources. 

Highlights:

  • Flexible framework for developers to create an endless number of integrations.
  • Any API data system is eligible to integrate within Business Central.
  • Only basic technical requirements are needed to get started, with no coding necessary.

Suite Engine's solutions simplify business operations by seamlessly integrating Business Central with other essential tools, automating tasks, and delivering real-time insights.

Let's understand What API pages are - 

  • Pages of the type API are used to create versioned, webhook-supported, OData v4 enabled REST web services. 
  • This type of page cannot be displayed in the user interface but is intended for building reliable integration services. 
  • When creating this page type, you must specify a number of properties that provide information for the web service endpoint. 
  • Use the snippet tpage - Page of type API to get the right template and the list of these properties automatically filled in. 
  • This page type cannot be extended by creating a page extension object. Instead, you must create a new API by adding a page object.

For our integration demo we will add an PI page that will allow us to read the attachment from business central or write the attachment for business central.

Mandatory Properties for API Pages - 
  • Specify APIVersion, APIPublisher, APIGroup, EntityName, and EntitySetName for your API page. These properties will affect your custom endpoint.
  • Make Sure that ODataKeyFields is set to a GUID Field. If you are using version BC16 or lower then you will need to add GUID Field in your table.
  • For Business Central 2020 Wave 2 (BC17) you can utilize the system field from Microsoft as discussed in this article. I think the main reason of adding these fields in every table by Microsoft is to make integration easier.
For our Example we will add two new fields - 
  • In64BitValue    - This variable will be used to key-in Bit 64 value from external application.
  • Out64BitValue - This variable will be used to send Bit 64 value to external application.


Also to populate value of Out64bitvalue, we will set that in OnAfterGetRecord using a function as below.


And below are the fields in the API Page that are added.
System ID field need to be added in API Page (or GUID Fields that you used in ODataKeyFields).



In next article we will start testing the customization that we developed.

Stay Tuned. Let me know your views as comment to this article.

Regards,
Saurav Dhyani

Comments

  1. Hi Saurav, thanks for the excellent content, is it possible to add a copy button to your above code such that you can just copy the code and paste it to AL.

    ReplyDelete
    Replies
    1. The Source Code is in github - https://github.com/postsaurav/ImportAttachment-API

      Delete

Post a Comment

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing -