Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

    Domino V10 - HTTP Requests and REST Services from Lotus Script

    Daniel Nashed  11 October 2018 00: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.maxredirects5
            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 = body.ContentAsText
           
            Call stream.Close
            Set doc = Nothing
    End Function
    Comments

    1Brian Benson  11.10.2018 5: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 9: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 10:20:24  Domino V10 - HTTP Requests and REST Services from Lotus Script

    How to set proxy?

    4Karli  11.10.2018 11: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 13: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 18: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

    Archives


    • [IBM Lotus Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]