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

Popular posts from this blog

TIP: Working with changing Field DataTypes and Deleting fields in Business Central

Introduction:
Imagine a scenario where as per the requirements provided by your clients, you have set up the Database structure in NAV/Business Central.
Then comes a requirement in Phase 2 which completely redefines the database structure which was provided by you and you need to delete a few fields in a table and move it to another table.

Pre-requisites:
Microsoft Dynamics NAV
Microsoft Dynamics Business Central

Books & References:
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-obsoletestate-property

Solution:
1. In Microsoft Dynamics NAV, there was a flexibility to delete fields, tables, and keys and using  Force-Sync, you can directly delete the field, table, and keys from SQL Database.


2. Whereas in Microsoft Dynamics Business Central, you cannot delete the fields, keys, and tables.
In order to deploy this deleted change, you need to mention this field, table, and keys with Obsolete State Removed.


After you mention the field as…

How to actually use Profile Objects in Business Central

To 'Whomsoever This May Concern',
When I was working on a Production Deployment for one of my clients, I noticed that I could not create a Profile in Business Central Production Tenant. I was able to create new Profile in Sandbox.


Then I tried using configuration Package and modify the contents of 2000000178 Profile Table and as always configuration package blocked it.



There was no way of dealing with this other thancontacting Microsoft Support and this is the answer I get from a Support Engineer

I was on the verge to give my clients a link pointing to a specific page i.e https://businesscentral.dynamics.com/?page=50150

After being a little creative, I figured out that developing profile objects might help.

And this resolved this issue for me.




Permission Issues on Posting after deploying Extension in Business Central Production Tenant

Introduction:
Issues when you deploy your app in Business Central Production VS Business Central Sandbox. Let us what are the implications of the statement.
In my last blog () I have already pointed out the difference in Profile as to how can create new Profile in Business Central Sandbox but the same is not possible in Business Central Production.
Pre-requisite:
Microsoft Dynamics Business Central (SaaS)
Demonstration: 1. I was working with General Journals after deploying the App in Production Environment. Suddenly during posting I go this error.


2. To Verify this issue is not of Permission Set, I gave the User SUPER Permission and tried again.

I got the same error despite giving SUPER Permission. Again the same the error, so I checked the Effective Permissions.

I noticed that Table G/L Entry has an Indirect Permission. I replicated the same Production in Sandbox. But I didn’t find any issue like this.

3. Moreover, I noticed that when I uninstall the App, the Production works perfectly and …