Hi! I'm trying to connect to a REST Api.
I'm using XMLport to send and receive the JSON and looks like it works fine until the response.
HttpWebRequestMgt.Initialize(URL);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.SetContentType('application/json');
HttpWebRequestMgt.AddBodyBlob(ReqTokenTempBlob);
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(InStr);
IF NOT HttpWebRequestMgt.GetResponse(InStr, HttpStatusCodes ,HttpResponseHeader) THEN
[...]
I thought that my variables may not be the ones that the function needs, so here are the ones im using:
HttpWebRequestMgt Codeunit Http Web Request Mgt.
HttpResponseHeader DotNet System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
HttpStatusCodes DotNet System.Net.HttpStatusCode.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
There may be an easier way to do this. So i'm open to hear whatever opinions & tips you guys may have.
Thanks in advance
Answers
What does the API documentation say? Do you need to send data with your request in some other way as as part of the URL?
I am not aware of the option to process JSON with an XML Port. When did this get added?
I always just used the variables and created my own codeunit to easily do API calls.
This is not an exact copy of it, but it might help you.
The documentation says that the first contact should be with user/pwd/licensekey in order to get the auth token. In fact, using postman (an app to test those connections) with the same info is working nicely.
The translation would be something as "the connection was forced to stop because of the remote host"
im following an old post from Gunnar's blog and adapting it to my needs. So my guess is that its a few years old, at very least 6!
I'm going to give this a try! Thanks
edit: Btw @Resolus , HttpClient variable is ->
System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' right?
The example above is from AL, but below should be the variables for C/AL
That explains it pretty much. XMLPort does not support JSON directly but XML can be convertetd to JSON and JSON to XML.
So i've tried to use some of the options I got here, and the: But i cannot get the response either...
It's not implemented but a useful workaround, the thing is not that the conversion isn't working, is the connection with the API. The conversion works pretty fine at the moment.
And yes, i need to send user/pasword/acceskey to verify everything so thats why i'm trying to send the json too
I've looked into our pre-AL code, and it seems you might only need to add .Result at the end to get the right object.
Thanks for checking that and telling me, I'm still having some threading errors.
I will try to fix those and reply with the result! Thanks in advance!