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

Universal Code Error and Resolution

Introduction: On Friday, May 12th, 2023, the Business Central On-Premise Production Environments started throwing universal code errors as follows. This occurred to every customer on a lower version of BC 19,20 and 21 irrespective of their localization, customization, and license. Pre-requisites:  Understanding of Technical Upgrade in Business Central On-Prem References: BC20 On prem. Universal Code requirement error after installing customer's license. - Dynamics 365 Business Central Forum Community Forum (40) Yammer : Dynamics 365 Business Central Development : View Conversation Root Cause: The certificate that signs Microsoft Base Application was expired. Errors started occurring if you Uninstalled, Installed Extensions, Restart Server Instances or for some even out of random started popping out. We first thought could be a license issue as we had fixed that before but this did not solve the issue. Resolution: Microsoft identified the issue and posted the following update The mi

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 Editworkshe