How to send API requests to Automai RPA using Jenkins?

This article will walk you through the format and syntax used when making Automai RPA API requests using Jenkins. In this article, we will create a pipeline (Jenkins job) for each request using Groovy code and then build the pipelines.

Note: You can use any other methods to configure your Jenkins jobs and run them. 

Automai RPA API requests using Jenkins

Generate Token

Go to Jenkins Dashboard and click "New Item".

Enter a name for the item, select "Pipeline" and click "OK". i.e. Generate Token

Put a description for the pipeline and put the script below in the Script section of the Pipeline.

Click "Apply" and "Save".

This authenticates the user with the Manager, and obtain a token.

Script:

def post = new URL("http://IP Address:port number/api/generatetoken").openConnection();
def message = "username=[username]&password=[password]"
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
println(postRC);
if(postRC.equals(200)) {
println(post.getInputStream().getText());
}

Example:

def post = new URL("http://172.169.12.51:8888/api/generatetoken").openConnection();
def message = "username=admin&password=admin"
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
println(postRC);
if(postRC.equals(200)) {
println(post.getInputStream().getText());
}

Response:

[Token Value] i.e. 6d83469eea9ffc77431c0013aeb944170a1699513f39

Create and play a Process Flow Run 

To create a new pipeline for the next request, go back to Jenkins Dashboard and click "New Item".

Enter a name for the item, select "Pipeline" and click "OK". i.e. Create and Play Process Flow Run

Put a description for the pipeline and put the script below in the Script section of the Pipeline.

Click "Apply" and "Save".

This takes the Process flow ID as input and creates a Process flow run based on an existing Process flow. Then it finds the available rWorkers and have them start executing the processes.

Script:

def post = new URL("http://IP Address:port number/api/createandplayfr").openConnection();
def message = "f_id=[Process Flow ID]"
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Authorization", "Token [Token Value]")
post.setRequestProperty("Accept", "application/xml")
post.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
println(postRC);
if(postRC.equals(200)) {
println(post.getInputStream().getText());
}

Example:

def post = new URL("http://172.169.12.51:8888/api/createandplayfr").openConnection();
def message = "f_id=APF-65621"
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Authorization", "Token 6d83469eea9ffc77431c0013aeb944170a1699513f39")
post.setRequestProperty("Accept", "application/xml")
post.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
post.getOutputStream().write(message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
println(postRC);
if(postRC.equals(200)) {
println(post.getInputStream().getText());
}

Response:

The Process flow (i.e. APF-65621) will start playing.

Tip: You can find the desired Process flow ID next to the Process flow name in the "Process Flows" section.

When you create your pipelines, there will be two pipelines listed in your Jenkins view. Now you can start running your jobs by building your first pipeline (i.e. Generate Token ) and use the output to run the next pipelines.