0

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 !

G. Trennert
  • 561
  • 3
  • 12
  • 23

2 Answers2

1

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

azatoth
  • 705
  • 6
  • 14
1
  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.

Mak Sim
  • 2,148
  • 19
  • 30
  • Ok Yes I have seen that with nav2013 I can use .net librairies : http://msdynamicsnav.guru/wp/gunnar/json-meets-nav/00749/ I will try to understand how I can advantage of this – G. Trennert Oct 14 '15 at 17:55
  • Yes I imagine using NAS to automate the exchange - I only wonder how I should iniate a request to groupon and then how to receive the result of the request – G. Trennert Oct 14 '15 at 17:59
  • I don't have Nav 2013 here to provide .net example but posted good old automation example. I think it will work even in Nav 2013. Or you can rewrite it. – Mak Sim Oct 19 '15 at 14:14
  • Thank you - this gives me aready a little Idea how to begin :) – G. Trennert Oct 20 '15 at 18:24