G. Trennert
G. Trennert

Reputation: 571

Dynamics Nav exchange with Groupon

I need to build an interface between Dynamics NAV 2013 and Groupon API V2 It seems to me that Groupons API data comes in json format - how could I get this information in Dynamics NAV (orders for example) ? Should I use webservices ?

Thanks

EDIT : I worked a lot on this and got receiving data from groupon working The problem is send information : I have a problem to send a post request with parameters - this is my code :

WebServiceURL := 'https://...';
Request := Request.Create(WebServiceURL);
Request.Method := 'POST';
Request.KeepAlive := TRUE;
Request.Timeout := 30000;
Request.Accept('application/json');
Request.ContentType('multipart/form-data');
postString := 'param1=123&param2=456';
Request.ContentLength := STRLEN(postString); 
StreamWriter := StreamWriter.StreamWriter(Request.GetRequestStream);
StreamWriter.Write(postString);
StreamWriter.Close;

I get a 500 error so I don't know anything about why its rejected But if there is something that seems to be wrong to you, please help !

Upvotes: 0

Views: 294

Answers (2)

Mak Sim
Mak Sim

Reputation: 2324

  1. You don't need Nav web services because in this case you are (Nav) the client side, when web services is to build the server side. E.g. you can call web service but web service can not call anything. Most probably you will use NAS to perform tasks periodically.
  2. AFAIK Nav can't handle JSON, but in Nav2013 it's possible to use .Net libraries so just pick JSON library you like and call it from Nav to process responses from API.
  3. To make calls(requests) to API you can use .net or com library of your choise just the same was as for JSON.

    ReqXML :    Automation  'Microsoft XML, v6.0'.DOMDocument60
    RespXML:    Automation  'Microsoft XML, v6.0'.DOMDocument60
    Req    :    Automation  'Microsoft XML, v6.0'.XMLHTTP60
    
    CREATE(Req, TRUE);
    Req.open(reqType, Uri, FALSE);
    Req.setRequestHeader('contentType', 'text/xml; charset=UTF-16');
    
    CASE reqType OF
     'GET': Req.send();
     'POST': Req.send(ReqXML);
    END;
    RespText := Req.statusText;
    IF Req.status <> 200 THEN EXIT(FALSE);
    
    IF ISCLEAR(RespXML) THEN CREATE(RespXML, TRUE);
    RespXML.load(Req.responseXML);

In this example request to address stored in Uri is made. If you need to post some data aside from URL parameters then you put it to ReqXML. If API is suppose to return something it will be inside RespXML.

This code works for older versions of Nav. You will have to rewrite it a little to use .Net libraries (like webclient) and maybe get rid of XML (in my case API was XML based) but the structure will be pretty much the same.

Upvotes: 1

azatoth
azatoth

Reputation: 705

the most NAV frienly way is to get the order in XML format from the API and import the XMLs using XMLports or Codeunits(use DotNet)

Cheers

Upvotes: 1

Related Questions