Hi Readers,
I hope you are doing well. Here is another interesting blog for you all!
APIs give more feasibility over Web Services and have fewer restrictions than them. The data can also be in any format, and also provides the segregation over Page Cards which we had to create for Web services. Business Central gives a lot of facilities for APIs. You can also connect to external APIs without any hassle and access JSON parameters. But that is again for another blog.
Today, we’ll see how to create APIs pages and use GET, POST, PATCH and DELETE methods for CRUD operations, through Postman.
Let’s get started!
Prerequisites:
- Business Central Sandbox Environment
- Username
- Web Access key
The steps are as follows:
- Create an extension or add your code to your existing extension however you like it.
- Create a Table as shown below:
- Create an API page as shown below:
- Add your Page to the list of APIs in API Setup.
- Get the Postman ready. It should have Authorization as Basic Auth and Username and Password will be your Business Central Username and Web Access Key respectively.
The API url format: {busiesscentralurl}/v2.0/{tenantid}/Sandbox/{APIPublisher}/{APIGroup}/{APIVersion}/
Example:https://api.businesscentral.dynamics.com/v2.0/{tenantid}/Sandbox/api/Jyotsna/itemChars/v1.0/
- Send the request through Postman:
GET (Read):
Example:
https://api.businesscentral.dynamics.com/v1.0/{tenantId}/sandbox/api/Jyotsna/itemChars/v1.0/companies({companyId})/itemChars
POST (Insert):
Example:
https://api.businesscentral.dynamics.com/v1.0/{tenantId}/sandbox/api/Jyotsna/itemChars/v1.0/companies({companyId})/itemChars
Note: For PATCH/PUT and DELETE you need to add an additional Parameter in your Header and that is as eTag as shown below:
Make sure that eTag should have the format: W/"___"
You'll get the etag for every record in the GET/POST request.
PATCH (Update):
Example:
https://api.businesscentral.dynamics.com/v1.0/{tenantId}/sandbox/api/Jyotsna/itemChars/v1.0/companies({companyId})/itemChars({Guid})
DELETE (Delete):
Example:
https://api.businesscentral.dynamics.com/v1.0/{tenantId}/sandbox/api/Jyotsna/itemChars/v1.0/companies({companyId})/itemChars({Guid})
So, overall what happens is that we take an httpclient (business central) and send a httpRequest in any format (json in our case) using Headers (eTag, if required) and Basic Auth, and different methods (GET, POST, PATCH and DELETE) which will perform an httpResponse which we tested through Postman.
No comments:
Post a Comment