Sunday, December 23, 2018

How to Call an external API from NAV C/AL code




Hello All,

Greetings!

Hope you all are well.

This post will cover how to consume external SOAP API and for this, we would use DotNet variables, which would have some request parameter and response with base 64 code.
In SOAP API we must pass the same structure as per the API method would have. Some of you would be aware that could have multiple methods in a one API.
Therefore, Below I have used DotNet variables







By using these variables, I have written a Codeunit which create xml request and xml response, and then we pass as a parameter to CallWebAPIRequest method. Further, we get response and read with dotnet variables then convert it to base 64 code to .pdf file.   














Here in below screen I have created xml request by using XML Dom Codeunit, you can also use XMLPORT for this.











In addition, here we create a connection with external API and get response; I have just created this Codeunit for demo purpose so in CallWSTop10 method you can do error handling if connection fails due to unexpected issue.
If status code is 200 then out connection is successful one more thing I have used here networkcredential method to pass user and password otherwise, system will through unauthorized error while making connection. User and password we can pass in xml request depends on API request.










By calling this, we get response






In next post, we will cover how to consume Rest Web API.
Thanks.

No comments:

Post a Comment

How to Call an external API from NAV C/AL code

Hello All, Greetings! Hope you all are well. This post will cover how to consume external SOAP API and for this, we would u...