Domino V10 - HTTP Requests and REST Services from Lotus Script
Daniel Nashed – 11 October 2018 22:55:16
One of the long missed features in Lotus Script is to work with HTTP requests.
Since Notes/Domino V10 you can now use HTTP requests directly from Lotus Script -- For example to query data from a website or from a REST service.
In the beta I played around with it already. I was specially interested in authentication and HTTPS.
HTTPS now works and authentication can be implemented on your own. The a bit tricky part is the Base64 routine that you need for the authorization header. But there is a way to leverage the MIME classes for that.
So the following example helps you to get started. It builds the authentication header and also uses HTTPs to request a website.
Tip: Depending on the request you might run into issues with too many redirects which the function does not follow automatically. So you have to increase the limit as shown in the example.
For HTTPS the certificate needs to be verified. I have tested with my Let's Encrypt Certificated and it worked well.
Another tip: If you run into issues with certificates or other parts of the NotesHTTPRequest, there is a debug notes.ini setting Debug_NotesHTTPRequest=1.
I have tested the following example with the Notes V10 GA client.
The Designer help has some additional information also for the other functions of that class.
Enjoy
-- Daniel
Option Declare
Sub Initialize
Dim Session As New NotesSession
Dim ret As String
Dim URL As String
Dim headers As Variant
Dim user As String
Dim password As String
Dim webRequest As NotesHTTPRequest
Set webRequest = session.createhttprequest()
user = "john@acme.com"
password = "mypassword"
webRequest.maxredirects= 5
URL = "https://www.acme.com"
Call webRequest.Setheaderfield("Authorization", "Basic " + EncodeBase64 (user + ":" + password))
ret = webrequest.Get(URL)
headers = webRequest.GetResponseHeaders()
ForAll h In headers
MessageBox h
End ForAll
MessageBox ret
End Sub
Function EncodeBase64 (StrIn As String) As String
Dim session As New NotesSession
Dim stream As NotesStream
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Set stream = session.CreateStream
Call stream.WriteText (StrIn)
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Set body = doc.CreateMIMEEntity
Call body.SetContentFromText (stream, "", ENC_NONE)
Call body.EncodeContent (ENC_BASE64)
EncodeBase64 = Replace(Replace(body.ContentAsText, Chr(13),""), Chr(10),"")
Call stream.Close
Set doc = Nothing
End Function
- Comments [17]
1Brian Benson 11.10.2018 3:52:42 Domino V10 - HTTP Requests and REST Services from Lotus Script
Thanks, Daniel. I looked at the docs on this today but didn't find it very helpful.
Have you explored parsing JSON with LotusScript yet?
2Sean Cull 11.10.2018 7:00:25 Domino V10 - HTTP Requests and REST Services from Lotus Script
I have used this code from OpenNTF on a demo but it was a couple of years ago.
https://www.openntf.org/main.nsf/project.xsp?r=project/JSON%20LotusScript%20Classes/releases/D2FA35434F35EC4A8625777B004986F9
3Ed 11.10.2018 8:20:24 Domino V10 - HTTP Requests and REST Services from Lotus Script
How to set proxy?
4Karli 11.10.2018 9:29:31 Domino V10 - HTTP Requests and REST Services from Lotus Script
Did anyone successfully made a POST request to a https endpoint? I'm always getting strange results like access denied or 500 errors.
You can try this endpoint
https://ptsv2.com/t/bcy8z-1539248819/post
5Daniel Nashed 11.10.2018 11:31:16 Domino V10 - HTTP Requests and REST Services from Lotus Script
@Brian, I saw an example in a presentation but I have not used it on my own.
The purpose of my post was more to show how it works and specially what you have to do to get it working with https and authentication.
I am not working on an application based on it right now. I am working on other stuff for Domino V10 right now.
-- Daniel
6Alex 14.11.2018 17:51:16 Domino V10 - HTTP Requests and REST Services from Lotus Script
Karli, I succeeded in submitting POST actions to a REST Service with the help of 2 script libs from Robert Ibsen Voith.
Just tried the URL you posted...it works.
If you need help you can contact me: alex@docworks.net
7Amit Sharma 17.01.2019 5:30:13 Domino V10 - HTTP Requests and REST Services from Lotus Script
Hi Nash,
How is this different from MSXML2.XMLHTTP?
Does MSXML2.XMLHTTP have any advantage over NotesHTTPRequest?
If the requirement is collecting and analysing information of website as text, which method should be used -->
MSXML2.XMLHTTP or NotesHTTPRequest on V10.
Regards,
Amit Sharma
8Daniel Nashed 17.01.2019 10:07:15 Domino V10 - HTTP Requests and REST Services from Lotus Script
Hi Amit!
MSXML was an add-on not something that comes with Notes/Domino out of the box! And it only works on Windows!
The solution is also legacy as the Wikipedia entry says --> https://en.wikipedia.org/wiki/MSXML
Having it available directly in Lotus Script has a couple of benefits.
- Fully supported by IBM
- Works cross platform
- Does not need any deployment!
-- Daniel
9Frank Bueschler 04.02.2019 14:21:34 Domino V10 - HTTP Requests and REST Services from Lotus Script
We also had strange results with this code example. Took some time to figure out, that the EnodeBase64 function is adding line-feeds to the resturn string.
10Diogo Tocci 17.04.2019 17:02:04 Domino V10 - HTTP Requests and REST Services from Lotus Script
Is there an way to ignore SSL. Something like this (Node.Js)
let options = {
method: GET,
json: true,
uri : "https://" +this.urls + endpoint,
body: payload,
insecure: true (ignore https)
};
11Miguel Calvo 22.11.2019 16:30:16 Domino V10 - HTTP Requests and REST Services from Lotus Script
By the way, I tried your code with a POST request, but had problems with the EncodeBase64 method.
When using it, anything that was added to the WebRequest after using it got lost. For instance the POST parameter Value.
I had to replace it with this old resource from Julian Robichaux https://www.nsftools.com/tips/Base64v14.lss and everything was fine.
Thanks for the post,
Miguel
12Mark Reiser 03.08.2020 13:06:28 Domino V10 - HTTP Requests and REST Services from Lotus Script
Hello Daniel, hello Miguel,
I just found out why the EncodeBase64 function leads to an error.
The function´s result ends with character 13,10, meaning for http requests that the header ends.
I just had that problem, and it cuts the header so the content-lenght parameter was missing and the target API could not handle the request.
Daniel, please change this within your example!
Just cut the right most 2 chars if they are newline.
Best regards
Mark Reiser
13Bruce Kahn 22.08.2022 18:38:16 Domino V10 - HTTP Requests and REST Services from Lotus Script
@Ed:
A very belated answer to your proxy question. Proxy use/support is documented here: https://support.hcltechsw.com/csm?id=kb_article&sysparm_article=KB0073832
14Sean Cull 01.10.2022 23:01:48 Domino V10 - HTTP Requests and REST Services from Lotus Script
Thanks for this Daniel, the base64 function really helped me on a separate project.
15Tom 23.01.2023 20:36:23 Domino V10 - HTTP Requests and REST Services from Lotus Script
Anyone had any luck or experience using NotesHTTPRequest to upload a file (multipart/form-data)?
16Christian Gravgaard 18.07.2024 9:44:21 Domino V10 - HTTP Requests and REST Services from Lotus Script
Didn't you need to set webrequest.Preferstrings = True?
I kept getting a BYTE() array until I set Preferstrings.
Furthermore, is it just me, or is it really slow? I tried the curl approach, and it is lightning fast.
17Frank Bueschler 15.11.2024 10:18:00 Domino V10 - HTTP Requests and REST Services from Lotus Script
Does anyone has a solution for reducting traffic by setting header Accept-Encoding: gzip,deflate - how to unzip the result
18Daniel Nashed 15.11.2024 13:29:18 Domino V10 - HTTP Requests and REST Services from Lotus Script
@Frank, the HTTP class is text only. You can't get binary data back currently.
Also Lotus Script has no way to unzip data. Probably the best way would be using a Java based approach.