Skip to main content

#msdyn365bc - Test Base64 Conversion via API?

Hi Readers,

As discussed in last article we will Test customization using API that we developed this week for integration from #msdyn365bc or #MSDynNAV.

If you want to see other articles in this series please refer here.

We will need to use same website to Test this process. This process will require a Base64 Value for testing. 

To use API we will require URL to access the API Page. Let's understand that part.

Business Central 2020 wave 2 support API V1 and V2. In our example we have specified V1 in our API Page. So let's first build URL to access custom API Page that we have developed. 

URL is different based on environment -
** Parameters in Red Need to be replaced by actual values

For SaaS - https://api.businesscentral.dynamics.com/v1.0/<user domain name>/api/<API publisher>/<API group>/<API version>/companies(<company id>)/<entitySetName>

For Sandbox - https://api.businesscentral.dynamics.com/v1.0/<sandboxtenantid>/sandbox/api/<API publisher>/<API group>/<API version>/companies(<company id>)/<entitySetName>

For Docker - (Use https if you are using a certificate) - 
http://<containername>:<port>/<servicename>/api/<API publisher>/<API group>/<API version>/companies(<company id>)/<entitySetName>

For On-prem - (Use https if you are using a certificate) - 
http://<servername>:<port>/<servicename>/api/<API publisher>/<API group>/<API version>/companies(<company id>)/<entitySetName>

For our scenario (using docker container) let's set these values - 
  • Container Name - bc171ussandbox
  • port - 7048
  • service name - bc
  • API Publisher - sauravdhyani
  • API Group - demo
  • API Version - v1.0
  • Company id - 
  • EntitySetName - apiattachments
Other than first three parameters (which provide details of tenant) other parameters are based on what you set in your API Page.

Now last parameter that we are missing is Company id. In Business Central starting Business Central 2020 wave 2, Each record have a unique GUID using SystemID field in each table.

As there can be multiple companies in database you need to provide detail of company in which you would like to perform action. You can get company ID by doing a get in Postman or manually from the client. 

Call the Get using postman with URL and copy the company ID in which you would like to use - http://<containername>:<port>/<servicename>/api/<API publisher>/<API group>/<API version>/companies




Once you have company ID, your URL is complete like mine - 
http://bc171ussandbox:7048/bc/API/v2.0/companies(264f8dd2-4a2a-eb11-bb4f-000d3a25f2a9)/attachments

So let's start testing.

Let's do a get to check can we access existing records in database. We will use Get, Input API URL, Specify Authentication & select Send to get existing records in the database.

We will receive all required values in the database.



Now let's follow same steps as we did in last article to get Base64 value using Bit64 Guru website and copy the Base64 value.


Using this Base 64, lets Post a record using API (via Postman). 
Choose Post, Specify API URL, Select Body, Raw & JSon to add values of new record that we like to insert and then click Send.


Let's open business central to check records. And we will see new record inserted.


Now final test with Base64 out value, lets do a get again and copy the Out64bit value.


And using Base64Guru, lets decode the value to see the actual object.



This is the end of the series about External integration using web services or API. Hope you learned something from the series and will be able to utilize this information to develop great solution.

Let me know your views as comment to this article.

If you would like to use Media instead of blob in same example, please add that to comment and I will update source code.

If you would like to access the source code please refer GitHub.

Stay Tuned. Let me know your views as comment to this article.

Regards,
Saurav Dhyani

Comments

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing -