How to add my working code sample to Knowledge Base?

Hi, I have a working code sample of sending a get request and parsing its’ response using Java in Custom Actions Script feature in RPA Express. How can I add it alongside other code samples in Knowledge Base?

Hi Stuti,

Please publish your code on the forum in Custom Actions category with a tag code-sample. We will then add to the documentation.

Thanks a lot

1 Like

@ashapkina Thanks ! Please find my code below for sending a get request and parsing its’ response using Java in Custom Actions Script feature in RPA Express:

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;

    @CustomScriptAction(
        input = ['web_url'],
        output = 'response_of_url'
    )
     
    def customScript() {
        URL obj = new URL(String.valueOf(web_url));
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        int responsecode = con.getResponseCode();
        if (responsecode == HttpURLConnection.HTTP_OK) { 
           BufferedReader in1 = new BufferedReader(new InputStreamReader(con.getInputStream()));
           String inputLine;
           StringBuffer response = new StringBuffer();
           while ((inputLine = in1.readLine()) != null) {
               response.append(inputLine);
           }
           in1.close();

           response_of_url = RString.of(response.toString());

        } else {
           response_of_url = RString.of("GET request not worked");
        }
    }
3 Likes

Thanks a lot for sharing :+1:

We have a similar sample in the Knowledge Base in groovy.

1 Like

Yeah. Actually I was trying to make a POST request so before that I tried to do this and it worked well, so sharing it. Also, KB doesn’t have any example of POST request in groovy so please share if someone has that code.

Hi @stuti.verma, can you please help me with one query If my response is in the form of List<List> then how can covert that response into table variable?

example: [ [“test”, “color”], [“test1”, “color1”]]

@abhimanyu_thit You can iterate the List and save each value into a table variable using Expression feature under Variables tab.

1 Like