Skip to main content

Creating APIs in Business Central - 1

Introduction:
While writing a blog on Automated Testing in Business Central, I was going through sample apps provided by Microsoft and realized that the complexity is nowhere close to what examples Microsoft has provided on docs.microsoft.com. In this blog, I will try to explain how APIs work and how to be creative with the implementation. Also, an API which were in beta are finally out with version V1.0 in the April 2019 release let's see some important key things from development aspects.
This blog is going to be theoretical one kindly bear with me.


Pre-requisites:

Books & References:
  • API V1 from Business Central On-Premise DVD
  • API(V1.0) for Business Central (Click Here)
  • API(Beta) for Business Central (Click Here)

Solution:

Key Requirements:
API source table must have an Id(GUID) field per record for masters

API(Page) Properties:
  • APIGroup: Sets the group of an API endpoint that page is exposed in.
  • APIPublisher: Sets the publisher of an API endpoint that page is exposed in.
  • APIVersion: Sets the versions of an API endpoint that page is exposed in.
  • Caption: Caption for the API endpoint.
  • DelayedInsert: Sets a value that specifies whether a user must leave a record before it is inserted into the database
  • EntityName: Sets the singular name of an API endpoint that page is exposed in.
  • EntitySetName: Sets the plural name of an API endpoint that page is exposed in.
  • ODataKeyFields: Specifies the field to select when using OData.
  • PageType: Sets the type of Page to API. All APIs have this property as mandatory.
  • SourceTable: Defines the source table to get data from and to write the data to.
  • DeleteAllowed: Set to declare whether the page can delete the data from the source table.
  • InsertAllowed: Set to declare whether the page can insert a record into the source table.
  • ModifyAllowed: Set to declare whether the page can modify the record from the source table.
  • SourceTableView: Used to sort & filter the data.
  • SourceTableTemporary: Set whether the SourceTable is Temporary or no.
  • RefreshOnActive: Set this property on the page where you want to refresh the recent data on the page after the user navigates from another page.
  • ChangeTrackingAllowed: Sets whether the entity exposed through the OData API supports change tracking.
  • Editable: Sets whether the page allows READ/WRITE or READ ONLY.
API(Query) Properties:
  • APIGroup: Sets the group of an API endpoint that page is exposed in.
  • APIPublisher: Sets the publisher of an API endpoint that page is exposed in.
  • APIVersion: Sets the versions of an API endpoint that page is exposed in.
  • Caption: Caption for the API endpoint.
  • QueryType: Sets the type of Query to create.

Page Field Properties:
  • ApplicationArea: Sets the Application Area that applies to the control.
  • Caption: Caption for the field on the API endpoint.
  • Tooltip: Sets if the tooltips are provided for the control. Tooltips are set based on whatever is assigned.
  • Editable: Sets if the field allows READ/ WRITE or READONLY.
  • NotBlank: Sets a value to specify whether Users must enter a value.
  • Width: Sets the width of the control. Width is set as a number of characters and must be a fixed number when specified.
  • ODataEDMType: Specifies the Entity Data Model Type to be used for this node in the OData metadata. (Refer here: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/entity-data-model)
  • BlankZero: Indicates whether the system displays zeros (0) and No.
  • AutoFormatType: Sets a value that determines how data is formatted, together with the AL expression in the AutoFormatExpression Property.
  • ShowCaption: Sets whether the text that is specified by the Caption Property is displayed for the control.
Page Part Properties:
  • ApplicationArea: Sets the Application Area that applies to the control.
  • Caption: Caption for the field on the API endpoint.
  • EntityName: Sets the singular name of an API endpoint that page is exposed in.
  • EntitySetName: Sets the plural name of an API endpoint that page is exposed in.
  • SubPageLink: Sets the link between the parent page and the Card Page.

Query DataItems Properties: 
  • Caption: Caption for the field on the API endpoint.
  • DataItemLink: Sets a reference between one or more fields of the data item table and parent data item or data items.
  • SqlJoinType: Sets the data item link type between data items in a query to determine the records that are included in the resulting data set.
  • DataItemTableFilter: Sets filters on fields of the underlying table of a query.
Query Feilds Properties:
  • Caption: Caption for the field on the API endpoint.
  • Method: Gets or Sets method as defined in the HTTP standard(Aggregate Function)

When to use the Page and when to use Query in API: 

  • A query is used when data from the multiple tables is to be fetched and aggregated. For Eg: Total Sales for All the Customers.
  • A page is used when the data to be fetched from a single table. For Eg: Customer Master


Note: All the properties used are similar to pages & queries. Choose as suitable.

Conclusion:
In this blog, I've discussed the properties of API (Pages & Queries) which will help us in the creation of API and are crucial for understanding and development of custom APIs as well.
In my next blog(Click Here!), I'll show an implementation side in detail.

Hope this helps! :)

Comments

  1. Hello, maybe i am wrong but the last link dowsn't work (the clieck here! link)
    Thanks

    ReplyDelete
    Replies
    1. Please try again. Unfortunately Base URL is updated hence the cause :(.
      Thanks for suggesting :)

      Delete

Post a Comment

Let me know your comments below. I'll try my best to answer your comment

Popular posts from this blog

Something went wrong. An Error occurred - Error Resolution

Introduction: With the installation of NAV 2018 or BC On-premise, I have observed that when creating New Server Instance and New WebServer Instance, you will get the error 'Something went wrong. An Error occurred '. I referred to the community questions below but didn't find my resolution. Hence, I decided to write this blog. Pre-requisites: Microsoft Dynamics Business Central - On-Premise / NAV 2018 Understanding of Business Central Authentication  Books & References: https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/261301/nav-2018-web-client-an-error-has-occurred https://community.dynamics.com/business/f/dynamics-365-business-central-forum/421987/error-something-went-wrong-an-error-has-occurred-azure-ad-tenant Demonstration: 1. Creation of NAVServerInstance: In order to create NAVServerInstance, you can either add the Server Instance through Business Central Administration or Powershell command. Add Instance - Business Central Administration Add Insta...

How to resolve 'Edit in Excel' issues

  Introduction: As you know that D365 BC offers Edit in Excel functionality. But manipulating or customizing such a  standard functionality is difficult as there is not much control available. Hence, solving issues is also a difficult task. I will be resolving the issue for this specific issue, however, the debugging steps are similar. Pre- requisites : ODATA V4 Connectivity tool for Webservices Microsoft Dynamics 365 Business Central Books & References: https://community.dynamics.com/business/f/dynamics-365-business-central-forum/448226/issue-with-excel-add-in/ Demonstration: The way Edit in Excel works is that for a given page a Webservice is created adding PageID and Page Name. Hence, there are some Webservice connectivity checks in place to validate. 1. Edit in Excel Custom Action on the page: If you are adding Edit in Excel Action on the page, please ensure that you are providing appropriate PageName and Filter criteria as Webservice is using these parameters Refer Ed...

Installing LS Central - POS on local machine

Introduction: In this blog, I'm attempting to capture the LS Central - POS installation process on Local Machine. This blog has nothing to do LS Central - Server Setup for POS. LS Retail / LS Central - On Premise POS Pre- requisites : LS Central Installed on Server SSL Setup on LS Server (https://www.olisterr.tech/2020/03/how-to-setup-navuserpassword-with-ssl.html) LS - POS Installer Business Central - On Premise Installer Demonstration: Once your LS Retail / LS Central POS is setup on the main server. Just prior to Go-Live, you will actually have to install this POS on multiple systems and connect these POS to the main server with LS Retail / LS Central. 0.Preparation: Prior to actually installing Business Central On-Premise Windows Client, you need to make sure that you're able to ping the target with the correct Port number. For this I made use of PS-Ping tool.  PSPing - IP Address: Port If you're unable to PS-Ping the correct IP with Port number, simply check the Advan...