You can use either NTLM authentication
or Basic authentication
to access a NAV
web service. You can use Postman
, curl
or any of the popular programming languages.
Use NTLM authentication
when NAV is using the Windows
credential type. The username and password belong to the Windows
user added in NAV. The user must be enabled
in NAV. The username and password must be valid on the windows machine, that is, someone can login on the computer using them. Ensure that the checkbox Use NTLM Authentication
is checked in NAV Administration
. Postman has beta support for NTLM authentication.
Use Basic authentication
when NAV is using NavUserPassword
credential type. The user must exist in NAV and have a username and password. To supply the fields when making a request, Base64 encode the username and password combination, that is, base64 encode this: username:password. For example, if my username is jack and password is Jack@1234, the base64 encoded string I'll use is: amFjazpKYWNrQDEyMzQK . I've obtained it using below bash command:
echo 'jack:Jack@1234' | base64
Use the normal protocol for basic authentication to supply the authentication in the http request. See: https://learning.postman.com/docs/sending-requests/authorization/
Below is a guide on NTLM authentication using the httpntlm library in node.js. Another library you can use is axios-nltm.
For PHP developers, see this article on php ntlm authentication.
NTLM authentication
allows a client to access a resource on the server by providing credentials for a Windows account that exists on the server.
So if the server has a user named GilbertS
with a password Gilbert1000
, you can send a request to the server by running the following javascript code:
const httpntlm = require('httpntlm');
const NAV_DimQuery = "http://junit:7148/BC140/ODataV4/Company('CronusCompany')/MyDimensionQuery";
httpntlm.get({
url: NAV_DimQuery,
username: 'GilbertS',
password: 'Gilbert100',
domain: 'JUNIT'
}, function(err, res) {
if(err) {
throw err;
}
console.log(res);
});
Install the necessary library by entering the command: npm i httpntlm
Note that other languages like PHP and Java have a similar library.
To get the Domain name, from the command prompt or terminal of the server, run: SET
Look for the value of a key called USERDOMAIN
. Note that the domain can be left blank if the server is a PC and not a dedicated Windows Server.
NAV / Business Central specific configurations
In NAV or Business Central Administration, there is a field in the General tab called Use NTLM Authentication
ensure that it is checked (set to true). If you can not modify it from the NAV / BC Administration window, edit the CustomSettings.config
file in path: C:\Program Files\Microsoft Dynamics 365 Business Central\140\Service
.
Because we are using NTLM to authenticate, ensure that NAV / BC is configured to use Windows authentication
. You do so by setting the Credential Type
to Windows
.
If the Credential Type
is set to something else or you do not tick Use NTLM Authentication
, you will get an error when sending the request saying something like the server does not allow NTLM.
Also, make sure that the Windows user you are using to access data in NAV / BC exists in the Users table in NAV / BC and that user is enabled.
If the NAV server is using NavUserPassword authentication, you can create another server instance that uses Windows authentication for the same database.
Finally, beware of a certain case where running the code makes the NAV Server to stop, I am still trying to figure out what causes this.
You can make inquiries in the comments in case there is something that is still making your requests to fail.
I've created two npm libraries to help with NAV / BC web service integration.
A library that makes creating a URL to send to the web service to consume Odata simple and declarative:
https://www.npmjs.com/package/navodata
A client built on top of httpntlm
library for accessing a web service using windows authentication. Provides error handling and use of promises:
https://www.npmjs.com/package/navclient