Dynamics Nav exchange with Groupon - microsoft-dynamics

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 !

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

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.
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.
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.

Related

Provider not exported in Delphi SOAP Server + Client

I'm using Delphi XE7 + Employee Interbase DB.
I'm tryin to build a SOAP server with Datasnap.
I have 3 SOAP Server Data Modules in one server, each one with a table: Customer, Employee, Country, each one made the same way (File, new, other, SOAP Server Data Module), then from Data Explorer dragging a table on the data module (Delphi creates a TSQLCOnnection and a TSQLDataset), then adding a TDatasetProvider. The three Data Modules are identical.
In the client application i have three interfaces made by WSDL importer
ICountryWM = interface(IAppServerSOAP)
['{1DA001BC-4DFB-E7F8-F62D-DA3545B334DC}']
end;
The three interfaces are identical (of course names and GUIDS are different).
In the Client form i have three buttons, they doperform the same operations:
procedure TClientFM.BtnEmployeeClick(Sender: TObject);
begin
ClientDataSet.Close;
SoapConnection.Close;
SoapConnection.UseSOAPAdapter := False;
SoapConnection.SOAPServerIID := '{02E9AB9B-DB17-ACF5-68D9-73FC763C04DC}';
SoapConnection.URL := 'http://localhost:8080/soap/IEmployeeWM';
ClientDataset.ProviderName := 'EmployeeProvider';
SoapConnection.Open;
ClientDataSet.Open;
end;
only changing ServerID, URL, ProviderName.
The three DatasetProvider ini the three Data Module have "Exported" checked.
In the beginning the first SOAP Server Data Module (Customer) worked well: from my client i sawe the Customers table. When i tried Employee or Country, i always got "Provider not exported".
I made a BIG MISTAKE: trying to change something i unchecked the Exported flags, compiled and ran server and client: nothig worked.
Ok, i expected that.
Then I rechecked the flags ... now the Exported flags are checked but no one provider works correctly ... (yes, the one that worked now does not work).
Both Server and Client run in the same PC.
Can someone give me any idea of what is wrong?
I think the problem is in the server, but WHERE in the server?

Connect to web service in MS Access with VBA

Is it possible to connect to a web service (for example send a HTTP Request) via VBA in Microsoft Access?
For example, the user clicks a button on a form, then a HTTP Request is sent to a web service that responds with OK.
Has anyone done this before?
Note: VBA, not VB.NET.
This is code I've used quite successfully with Access 2003. It's from the interwebs, copied and re-copied ages ago. It creates a XMLHttpRequest Object, sends an HTTP GET request, and returns the results as a string.
Public Function http_Resp(ByVal sReq As String) As String
Dim byteData() As Byte
Dim XMLHTTP As Object
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "GET", sReq, False
XMLHTTP.send
byteData = XMLHTTP.responseBody
Set XMLHTTP = Nothing
http_Resp = StrConv(byteData, vbUnicode)
End Function
sReq is the URL; the function returns the response. You may need to make sure ActiveX Data Objects are enabled under your References (in the VBA editor, go to Tools > References).
This is the code , which I used. You need to first reference Microsoft XML V6 for this code to work.
Public Sub GetPerson()
'For API
Dim reader As New XMLHTTP60
reader.Open "GET", "www.exmple.com/users/5428a72c86abcdee98b7e359", False
reader.setRequestHeader "Accept", "application/json"
reader.send
Do Until reader.ReadyState = 4
DoEvents
Loop
If reader.Status = 200 Then
Msgbox (reader.responseText)
Else
MsgBox "Unable to import data."
End If
End Sub
I have used the "Microsoft Office 2003 Web Services Toolkit 2.01" toolkit (available here) on a few projects. It worked pretty well for me, although I also wrote the web services it was talking to, so I had the luxury of being able to fiddle with both ends of the process when getting it to actually work. :)
In fact, I just upgraded one of those apps from Access_2003 to Access_2010 and the SOAP client part of the app continued to work without modification. However, I did encounter one wrinkle during pre-deployment testing:
My app would not compile on a 64-bit machine running 32-bit Office_2010 because it did not like the early binding of the SoapClient30 object. When I switched to using late binding for that object the code would compile, but it did not work. So, for that particular app I had to add a restriction that 64-bit machines needed to be running 64-bit Office.
Also, be aware that Microsoft's official position is that "All SOAP Toolkits have been replaced by the Microsoft .NET Framework." (ref. here).

How to call Soap\WSDL Service through a login required webpage using matlab?

I am new to the wsdl\soapmessage query\reply world( if i can put it in this way), and I am facing some difficulties using the following wsdl( which I really really hope, one will be so kind to look at at least one of the services described there)
http://almdemo.polarion.com/polarion/ws/services/TrackerWebService?wsdl
which was provided to me to develop a matlab webinterface. Right now my matlab code looks like this:
targetNamespace = 'http://ws.polarion.com/TrackerWebService';
method = 'queryWorkItems';
values= {'Query','Sort'}
names = {'query', 'sort'}
types ={'xsd:string','xsd:string'}
message = createSoapMessage( targetNamespace, method, values, names, types)
response = callSoapService('http://almdemo.polarion.com/polarion/ws/services',...
% Service's endpoint
'http://almdemo.polarion.com/polarion/#/workitems',...
% Server method to run
message)
% SOAP message created using createSoapMessage
author = parseSoapResponse(response)
Herewith to save you time I will just enonce my two problems:
Is the code correct?
Could someone tell me if such a wsdl link is just a definition of webservices or it is also a service's endpoint?
Normally to execute manually\per clicks this services on the weppage
http://almdemo.polarion.com/polarion, you have to login!
So how do I send a message in matlab which first log me in? Or must such a service be introduced into that wsdl for me to do it?? Could you be kind enough to write how it must be defined, because I don't really
write wsdl files, but I shall learn!**
I will be really thankful for your help and I wish you a happy week(-end) guys(& girls)!!!
Regards
Chrysmac
ps: I tried to use Soapui and gave that webpage as endpoint, but the toool crashes each time I enter my credentials! Maybe because of the dataload!??

Delphi 7 CGI web service global parameter

I need to set a global parameter in the Webmodule of my Delphi CGI webservice so that I can use it throughout the life of the request as a unique identifier (traceId) for logging purposes. The unique identifier needs to be generated in the Webmodule because the first thing I log is the raw XML that is received. I then log all sorts of debug information in my actual web service methods and I needs the Id to tie these all together.
I can't figure out a way to do this. The actual Webmodule is not accessible in my webservice methods and any attempts just throw an access violation. I'm probably doing this in completely the wrong way but I can think of another solution.
Any ideas?
Assuming you're talking about a SOAP webservice, you can use GetSOAPWebModule to get a reference to your web module from within your service method.
Example:
uses
WebBrokerSOAP, MyWebModuleUnit;
procedure TMyService.MyMethod;
var
MyWebModule: TMyWebModule;
TraceID: Integer;
begin
MyWebModule := GetSOAPWebModule as TMyWebModule;
TraceID := MyWebModule.TraceID;
end;

Ways to implement a JSON RESTful service in C/C++

I am trying to do a JSON Restful web service in C/C++.
I have tried Axis2/C and Staff, which work great for XML serialization/deserialization but not for JSON.
You might want to take a look at Casablanca introduced in Herb Sutter's blog.
there are a small number of libraries that support creating rest services with c, e.g. restinio:
#include <restinio/all.hpp>
int main()
{
restinio::run(
restinio::on_this_thread()
.port(8080)
.address("localhost")
.request_handler([](auto req) {
return req->create_response().set_body("Hello, World!").done();
}));
return 0;
}
try https://github.com/babelouest/ulfius great library to build C/C++ Restful APIs. can support all platforms: Linux, FreeBSD, Windows and others
Try ngrest. It's a simple but fast C++ RESTful JSON Web Services framework. It can be deployed on top of Apache2, Nginx or own simple http server.
Regarding Axis2/C with JSON. It's seems that official Axis2/C no longer maintained. So Axis2/C become obsolete (but still works).
JSON support for Axis2/C is available in axis2c-unofficial project.
There are an installation manuals on how to install Axis2/C with JSON support under Linux, Windows using binary package, Windows from source code.
You can try it with WSF Staff using Customers (REST) example in JSON mode (which is available from staff/samples/rest/webclient directory of staff source code).
You could look at ffead-cpp. Apart from providing support for json and restfull web services it also includes more features. This framework may be too heavy weight for your situation though.
For C++ web service, I am using the following stack:
ipkn/crow C++ micro web framework
nlohmann/json for json serialization/deserialization.
Take a look at Oat++
It has:
URL routing with URL-parameters mapping
Support for Swagger-UI endpoint annotations.
Object-Mapping with JSON support.
Example endpoint:
ENDPOINT("GET", "users/{name}", getUserByName, PATH(String, name)) {
auto userDto = UserDto::createShared();
userDto->name = name;
return createDtoResponse(Status::CODE_200, userDto);
}
Curl:
$ curl http://localhost:8000/users/john
{"name":"john"}
You may want to take a look at webcc.
It's a lightweight C++ HTTP client and server library for embedding purpose based on Boost.Asio (1.66+).
It's quite promising and actively being developed.
It includes a lot of examples to demonstrate how to create a server and client.
There is a JIRA project resolved the support of JSON in AXIS2/C .
I implemented in my project and I managed with the writer (Badgerfish convention) but still I am trying to manage with the reader.It seems more complicated managing with the stack in the memory.
JSON and JSONPath are supported for both C and C++ in gsoap with a new code generator and a new JSON API to get you started quickly.
Several JSON, JSON-RPC and REST examples are included. Memory management is automatic.
The code generator can be useful. Take for example the json.org menu.json snippet:
{ "menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}
}
The gsoap command jsoncpp -M menu.json generates this code to populate a JSON value:
value x(ctx);
x["menu"]["id"] = "file";
x["menu"]["value"] = "File";
x["menu"]["popup"]["menuitem"][0]["value"] = "New";
x["menu"]["popup"]["menuitem"][0]["onclick"] = "CreateNewDoc()";
x["menu"]["popup"]["menuitem"][1]["value"] = "Open";
x["menu"]["popup"]["menuitem"][1]["onclick"] = "OpenDoc()";
x["menu"]["popup"]["menuitem"][2]["value"] = "Close";
x["menu"]["popup"]["menuitem"][2]["onclick"] = "CloseDoc()";
Also reading parsed JSON values and JSONPath code can be generated by this tool.
EDIT
To clarify, the jsoncpp command-line code generator shows the API code to read and write JSON data by using a .json file as a template, which I found is useful to save time to write the API code to populate and extract JSON data. JSONPath query code can also be generated with this tool.
For web service in C, you can leverage library like ulfius, civetweb:
https://github.com/babelouest/ulfius
https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md
For web service in C++, you can leverage library like libhv, restbed:
https://github.com/ithewei/libhv
https://github.com/Corvusoft/restbed