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

 
alt

Daniel Nashed

 

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

    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

    7Amit Sharma  17.01.2019 6: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 11: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 15: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 19: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 17: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 15: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

    Links

      Archives


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