Thursday, July 12, 2018

How to use POSTMAN for MS DYNAMICS NAV 2018 API /MS BUSINESS CENTRAL?

Hi ,

If you have not read my earlier post than please go to below link before moving further in this blog

post.

API Creation in NAV and Setup

So I am going to give you an example of NAV API where I can insert , update , modify and delete

data using postman in database.

What is POSTMAN ?

As a NAV developer , I am new to this term but world is so advance and we need to be with them.

POSTMAN is basically a testing tool for and API.

As I understood one thing API is nothing but a URL which will give me data and do other things 

which will help me out in transaction. So I will never be interacting with original database.

POSTMAN has some attributes methods which interact with API.

What are attributes we have in POSTMAN?

POSTMAN can be downloaded from this LINK

There are 4 main transactions we do in any database.

1. Insert for this POSTMAN has POST

2. Delete for this POSTMAN has DELETE

3. Modify for this POSTMAN has PATCH

4. Select for this POSTMAN has GET

GET all API from NAV :

GET http://NAV2017:7048/DynamicsNAV110/api/beta/$metadata


GET http://nav2017:7048/DynamicsNAV110/api/beta/companies


How to get company information using API ID FIELD?

GET http://NAV2017:7048/DynamicsNAV110/api/beta/companies(68a76662-a198-477b-8097-d9df2116514a)/companyInformation


How to create a Customer or any entity in NAV?

POST http://desktop-jsuo248:7048/DynamicsNAV110/api/beta/companies(cbc66cd3-c138-4bfb-81f8-c5142f303a15)/customers

ENTER THE RAW FORMAT AS SHOWN IN SCREEN :


How to modify a Customer  or any entity in NAV?

PATCH http://desktop-jsuo248:7048/DynamicsNAV110/api/beta/companies(cbc66cd3-c138-4bfb-81f8-c5142f303a15)/customers(d39e6dfa-dfcf-4524-b02a-93d8c8967562)



How to delete a Customer or any enitity in NAV ?

DELETE http://desktop-jsuo248:7048/DynamicsNAV110/api/beta/companies(cbc66cd3-c138-4bfb-81f8-c5142f303a15)/customers(d39e6dfa-dfcf-4524-b02a-93d8c8967562)



How to use FIlters in API URL?

GET http://desktop-jsuo248:7048/DynamicsNAV110/api/beta/companies(cbc66cd3-c138-4bfb-81f8-c5142f303a15)/items?$filter=unitPrice%20gt%20100

How to get details about any Sales Invoice or any document from NAV?

GET http://desktop-jsuo248:7048/DynamicsNAV110/api/beta/companies(cbc66cd3-c138-4bfb-81f8-c5142f303a15)/salesInvoices(9dec16d6-122b-4ed3-ba0f-ac62dd562409)?$expand=salesInvoiceLines




Last 2 methods for creating Sales Invoices and posting it can be checked at








Tuesday, July 10, 2018

How to open a desired Page in NAV and get the selected VALUE?

This is small code snippet but very power Code to provide user functionality.

This code will open a desire page and developers can get a user input in a variable and use it to run

the functionalty.


DimensionValue.RESET;
DimensionValue.SETRANGE("Dimension Code",'INSTITUTE');
IF PAGE.RUNMODAL(0,DimensionValue) = ACTION::LookupOK THEN BEGIN
  InstituteCode := DimensionValue.Code;
END;


I hope this will help developers community for fast review.

How to send SMS from MS Dynamics NAV or Business Central?

Hi ,

Below is the method to send SMS from NAV. It is a powerful tool we can achieve via using API.

Now all data centers are moving towards API.

So Dynamics NAV is also capable of using these APIs at a extreme level. Codeunits are now

available to developers for example CU 1290 ,1297 ,1299.

So below method I had used to send SMS and I am sure this method we can use for any API

integration in NAV.

Prerequisite :

API Credentials UserName and Password.

In my solution I had created 2 functions

Function 1 : CallRestWebService

Parameters :

Var Name DataType Subtype Length
No BaseURL Text

No Method Text

No RestMethod Text

Yes HttpContent DotNet System.Net.Http.HttpContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'


Yes HttpResponseMessage DotNet System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'



Variables in this function :

Name         DataType Subtype     Length
HttpClient DotNet         System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'


Uri DotNet System.Uri.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'


Code of This Function :

LOCAL CallRestWebService(BaseURL : Text;Method : Text;RestMethod : Text;VAR HttpContent : DotNet "System.Net.Http.HttpContent";VAR HttpResponseMessage : DotNet "System.Net.Http.HttpResponseMessage")

HttpClient := HttpClient.HttpClient();
HttpClient.BaseAddress := Uri.Uri(BaseURL);
CASE RestMethod OF
  'GET':    
    HttpResponseMessage := HttpClient.GetAsync(Method).Result;
  'POST':   
    HttpResponseMessage := HttpClient.PostAsync(Method,HttpContent).Result;
  'PUT':    
    HttpResponseMessage := HttpClient.PutAsync(Method,HttpContent).Result;
  'DELETE': 
    HttpResponseMessage := HttpClient.DeleteAsync(Method).Result;
END;
HttpResponseMessage.EnsureSuccessStatusCode(); // Throws an error when no success


Function 2 : SendSMS

VARIABLES

Name DataType Subtype Length
_StudentCollege Record Student - COLLEGE

Window DotNet Microsoft.VisualBasic.Interaction.'Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

data Text

httpUtility DotNet System.Web.HttpUtility.'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

encoding DotNet System.Text.Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

stringContent DotNet System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

HttpResponseMessage DotNet System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'


Code of Function :

MessageText := Window.InputBox('Enter your message to Send :','INPUT','',100,100);

_StudentCollege.SETRANGE("Global Dimension 1 Code",InstituteCode);

IF _StudentCollege.FINDSET THEN  

  REPEAT

    data := 'User=' + httpUtility.UrlEncode('USERNAMECREDENTIAL',encoding.GetEncoding('ISO-8859-1'));

    data += '&passwd=' + httpUtility.UrlEncode('PASSWORDCRENDENTIAL',encoding.GetEncoding('ISO-8859-1'));

    data += '&mobilenumber=' + _StudentCollege."Mobile Number";

    data += '&message=' + httpUtility.UrlEncode(MessageText,encoding.GetEncoding('ISO-8859-1'));

    data += '&sid=SMSCntry&mtype=N&DR=Y';

    stringContent := stringContent.StringContent(data,encoding.UTF8,'application/x-www-form-urlencoded');

    CallRestWebService('http://api.smscountry.com/SMSCwebservice_bulk.aspx?',
                                                       '',
                                                       'POST',
                                                       stringContent,
                                                       HttpResponseMessage);
  UNTIL _StudentCollege.NEXT = 0;

MESSAGE('Done');


How this code is working I will discuss in my next blog. 

Saturday, July 7, 2018

How to send SMS from MS Dynamics NAV or Business Central?

Requirement :

In my current solution , I need send SMS to my college students from NAV. I am using 

SMSCOUNTRY.IN as SMS provider.

Credentials will be provided once you approve the payment.

Solution :

The most amazing point is I achieved it with one single line of code. Developers can change the 

message TEXT mobile and SMS to send via AL code.

Thanks a lot to API.

HYPERLINK('http://api.smscountry.com/SMSCwebservice_bulk.aspx?User=USERNAME&passwd=PASSWORD&mobilenumber=MOBILENUMBER&message=FROM NAV&sid=SMSCntry&mtype=N&DR=Y');