Skip to main content

How to call a Kofax RPA Web Service from VB.NET

Article # 3035391 - Page views: 118


How to call a Kofax RPA RESTFul Web Service from a VB.NET code



  1. Open Design Studio.
  2. Deploy a robot that returns a complex variable.
  3. Open the Kofax RPA Management Console.
  4. Go to Repository > Robots and locate the robot.
  5. Click on the REST icon for that robot.
  6. Take note of the REST URL.
  7. Select the desired format for the request and copy the request string.
  8. Open Microsoft Visual Basic.
  9. Create a Web Form page with a button and a textbox
  10. Assign the code to call the service and to store the result in the textbox.

Here is a sample of this code:

 Protected Sub Btn_Sync_Click(sender As Object, e As EventArgs) Handles
    REST_URL =
'Enter your robot's REST URL
    REST_Request = 'this is an example where the pc name will be returned
            ""parameters"" : [ {
            ""variableName"" : ""restDemoINPUT"",
            ""attribute"" : [ {
                ""type"" : ""text"",
                ""name"" : ""INPUT_Info"",
                ""value"" : """ + Environment.MachineName + """
                } ]
             } ]
        REST_Response = ""
        'Invoke RESTFUL POST KAPOW Synchronous Dim JsonSring = REST_Request
        Dim myUri As New Uri(REST_URL)
        Dim data = Encoding.Default.GetBytes(JsonSring)
        REST_Response = Send_REST_Request(myUri, data, "application/json", "POST")
        'Send_REST_Request is documented below
        'Extract Result from XML
        Dim Xml As XmlDocument
        Xml = New XmlDocument
        Dim nodeList As XmlNodeList = Xml.GetElementsByTagName("attribute")
        For Each node As XmlElement In nodeList
            If node.Attributes(1).InnerText = "INPUT_Info" Then TextBox.Text =
              node.InnerText 'INPUT_Info is the variable returned by the web service.
    End Sub

    Private Function Send_REST_Request(uri As Uri, jsonDataBytes As Byte(), contentType
     As String, method As String) As String
        Dim req As WebRequest = WebRequest.Create(uri) req.ContentType = contentType
        req.Method = method
        req.ContentLength = jsonDataBytes.Length
        Dim stream = req.GetRequestStream()
        stream.Write(jsonDataBytes, 0, jsonDataBytes.Length) stream.Close()
        Dim response = req.GetResponse().GetResponseStream() Dim reader As New StreamReader(response)
        Dim res = reader.ReadToEnd()
        Return res
     End Function

NOTE: Note: if you are using Kofax RPA Enterprise under Tomcat, you have to configure the service authentication to prevent having an error (401) Unauthorized: Open the RPA Management Console. Go to Admin > Projects. Edit the project associated with your robot. Go to the Services tab Uncheck the "Authenticate REST/SOPA requests" checkbox. Note: when authentication is disabled, anyone with access to the application can invoke these services, so be careful when selecting which robots to put into this project. Optionally, you may fill in Access-Control-Allow-Origin to control which domains may call the service; you may use * to allow all.

Level of Complexity 



Applies to  

Product Version Build Environment Hardware
Kofax RPA all      


Add any references to other internal or external articles


Article # 3035391
  • Was this article helpful?