How to call Web Service (GET/POST) from MS Dynamics NAV C/AL


//Get
url := 'https://httpbin.org/ip';
CREATE(WinHttp);
WinHttp.Open('GET',url,FALSE);
WinHttp.Send(JsonTxt);
JsonTxt := WinHttp.ResponseText;
MESSAGE(FORMAT(JsonTxt));


//Post
url := 'https://reqbin.com/echo/post/json';
CREATE(WinHttp);
WinHttp.Open('POST',url,FALSE);
WinHttp.SetRequestHeader('Content-Type', 'application/json');

CREATE(XMLDoc);
NodeText := XMLDoc.createTextNode('');
NodeText.appendData('{ "Id": 78912');
NodeText.appendData( '"Customer": "Jason Sweet",');
NodeText.appendData('"Quantity": 1,');
NodeText.appendData( '"Price": 18.00}');
WinHttp.Send(NodeText.nodeValue);

JsonTxt := WinHttp.ResponseText;
MESSAGE(FORMAT(JsonTxt));



Variables:

Name

DataType

Subtype

Length

ResponseStream

InStream

 

 

ResponseBuffer

BigText

 

 

url

Text

 

1024

JsonTxt

Text

 

1024

WinHttp

Automation

'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest

 

NodeText

Automation

'Microsoft XML, v3.0'.IXMLDOMText

 

XMLDoc

Automation

'Microsoft XML, v3.0'.DOMDocument

 


Comments

Popular posts from this blog

Different use of AL Find Functions for Filters in Dynamics 365 Business Central

How to create documentation comment using Custom Snippets in VS Code for AL - D365 Business Central.

Microsoft Dynamics NAV - Creating and Consuming a Codeunit Web Service