Wednesday, December 9, 2020

#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.

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.

Saurav Dhyani

No comments:

Post a Comment

Popular Posts