Working with Business Central/NAV REST API v2 in SSIS

27 January 2022
KingswaySoft Team

Business Central supports three types of web services interfaces: API Web Service, SOAP, and OData. According to the Microsoft documentation, each interface supports accessing different objects. The following table lists the web services interfaces and the objects available in each of them.

Object

SOAP

OData

API Web Service

Pages

Yes

Yes

Yes

Codeunits

Yes

Yes

No

Queries

No

Yes

Yes

In previous posts, we discussed working with Dynamics 365 Business Central/NAV, SOAP and OData web services in SSIS using our SSIS Productivity Pack components.

In this post, we will delve into how to consume data with Dynamics BC/NAV REST API in SSIS using the Premium OData Source component, which is offered in our SSIS Productivity Pack.

Configure OData Connection Manager

To consume the Dynamics BC/NAV REST API, the first step is to configure the OData Connection Manager to establish a connection to the Dynamics BC/NAV server.

Connecting to Dynamics Business Central/NAV On-Premise

Dynamics BC/NAV On-Premise REST Base URL should have an address in the following format:

  • https://<HostName>:<port>/<serverInstance>/api/<API version>/?company='CompanyName'

A local Dynamics BC/NAV server can have a REST API base URL like this: https://nav.contoso.com:7048/bc/api/v2.0/?company='CRONUS%20Canada%2C%20Inc.'  After specifying the Base URL in OData Connection Manager, the next step is to configure the authentication in order to connect the Dynamics BC/NAV OnPrem server via proper authentication. When working with on-premises BC/NAV server, you would use the Credentials authentication method and provide the domain, username and password values.

Connecting to Dynamics Business Central Online

When working with Dynamics 365 Business Central online, the base URL for the REST v2 service endpoint should have a format like something below:

https://api.businesscentral.dynamics.com/v2.0/{tenant-id}/Production/api/v2.0/?company='CRONUS Canada, Inc.'

Both Basic and OAuth2 authentication modes can be used to connect to Dynamics Business Central Online.

When using Basic authentication mode, you would use the Business Central user’s Web Service Access Key as the password when setting up the Basic authentication. It is worth noting that the Basic authentication is not recommended for security reasons.

The preferred authentication would be using the OAuth option. In doing so, you will need to register an Azure Active Directory (AAD) application in the same Azure tenant in which your Business Central instance resides. Once you have created the Azure AD app, you will need to grant it proper permissions in order to access the Business Central services. The permission configuration should be something such as the example below:

After you have the Microsoft AAD app ready, you can now continue the configuration of the HTTP Connection Manager by setting the authentication mode to OAuth 2, and from there you can launch the OAuth Token Generator by clicking the Generate Token File... button. At this point, you should have all the required information which you can put into the OAuth Token Generator. Based on Microsoft OAuth documentation, we should configure the OAuth Token Generator like something below:

Parameter

Value

Sign In URL

https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/authorize

Client Id

The application ID of the AAD app.

Client Secret

The application secret in the AAD app.

Scope

https://api.businesscentral.dynamics.com/.default offline_access

Redirect URI

The redirect_uri configured in the AAD app

Click the Next button to go to the next page and click either the Authorize In App… or Authorize In Browser… button to launch the authorization page, from there you would log in and provide your consent to the permissions the app is requesting. Once done, you will be redirected to the redirect_uri web page that you have set up in the Microsoft AAD app. The URL will be appended with an authorization code in its code query string parameter. You would now copy the entire URL back to the pop-up dialog in OAuth Token Generator if you are using the Authorize In Browser mode, then you will be navigating to the Request Tokens page from where you can complete the process of obtaining a token for connection purposes.


In the Request Tokens page, Request Token URL should be “https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token” for Microsoft OAuth authentications. Fill in the Request Tokens URL and click the Get Tokens button to request an access token. If everything goes well, you should now have received the OAuth access_token along with a refresh_token. Now it is a good time to save the entire token as a file to your local file system which can be used for your connection manager later. When doing so, you will be prompted to provide a password to protect the sensitive fields in the token file.

Once the OAuth2 token file has been successfully generated and specified in the OData connection manager, the connection manager will automatically manage the lifecycle of the token, including the automatic refresh of the token when the current access token has expired. This provides you the maximum convenience for an uninterrupted integration process when it is used for unattended SSIS job executions. You can request the token file from one computer system, but upload it to another server for runtime execution.

Consume Business Central/NAV data using REST v2 API

After successfully creating and testing our OData connection, we are now ready to actually interact with the API to facilitate reading and writing data. This can be achieved using the Premium OData Source component which is offered in the SSIS Productivity Pack product. The Premium OData Source component is an enhanced OData Source component that supports working with entity, collection of entities, bound functions and unbound functions. It does a lot more than alternative solutions that might be available.

The screenshot below shows such an OData source component which retrieves contact records from Business Central/NAV REST API by working with the contact entity.

Conclusion

Dynamics Business Central/NAV data can be accessed using different API options, which include SOAP web service, OData web service, and the REST API endpoints. REST v2.0 API is a standard API offered by Microsoft that provides access to common objects in Business Central/NAV. Working with Business Central/NAV data through REST API in SSIS cannot be any easier when using the KingswaySoft Productivity Pack components. This way your integration can be done without writing a single line of code.

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags