In this article we’re going to look at Application Programming Interface (API) integration and how it can help your business become more effective and efficient.
API integration and automation go together. Quick system connectivity via APIs is one thing. Creating automation, while bringing API connectivity into your most important business processes is another.
Web API: REST Integration
REST is one of the most common web service being used by most web applications nowadays. The flexibility of using REST in any devices from desktops to mobiles appeals.
REST relies on a simple URL in many cases. In some situations, you must provide additional information in special ways.
The UiPath WebAPI allows you to manipulate REST API using the HTTP Request Wizard and can produce results in minutes.
Package Needed: Uipath.WebAPI.activities (Install and save the package for API Integration)
Activity used for API call: HTTP Request
After installing you will be able to find the HTTP Request activity from activities panel under App Integration » Web » HTTP Request
Properties for HTTP Request Activity:
The HTTP Request Wizard Panel
All fields in the wizard are also available in the Properties panel. So, you can edit your preferences even after closing the wizard. A function can be configured in the wizard using hardcoded values or variables.
The Request Builder Tab
End Point – Here you will give the URL which API you want to Integrate with UiPath
NOTE: When you use variable as a URL, the preview functionality is not useful.
Preview URL - The "Preview" of the URL in the HTTP Request activity, allowing you to see how the URL will look after incorporating those parameters.
Enable SSL certificate verification - You will check this box to verify the SSL Certificates while sending a Request.
Timeout - you can specify the TimeoutMS property, which sets the time in milliseconds that the activity will wait for the server to respond before throwing an exception due to a timeout. By Default it is 6000Ms.
Client Certificate – Give the File Path where the Client Certificate is Stored. Need to Provide the Full Path. It’s an optional field based upon sites.
Client Certificate Password - The password associated with the client certificate file you are using.
Request Method - The request method is an essential part to be used. Defines the type of HTTP request to be sent, such as GET, POST, PUT, DELETE, etc. By default, the GET method is taken.
Accept Response
· Any
· XML
· JSON
· Custom
Optional:
Cookie, body format (application/xml), Parameters, Headers will be able to give if needed.
Output:
Response content: will get the response status json/xml or another custom format (output from API).
Response Status: will get the response status code in integer format.
For Ex:
· OK 200
· CREATED 201
· Accepted 202
· Bad request 400
· Not Found 404
· Internal server error 500
File for response attachment: Here we will give the path to download the attachments from API endpoint.
Response Data Format
Json:
Maximum Cases will get the HTTP Request Response as to be a Json form. Json is nothing, it’s like a key/Value pair and each one is separated by comma. If we call the key will get the Token.
For Example:
{
"Car": {
"Make": "Toyota",
"Model": "Corolla",
"Year": 2022,
"Color": "Silver",
"Engine": {
"Type": "Gasoline",
"Displacement": "1.8L"
},
"Features": ["Air Conditioning", "Power Windows", "Sunroof"]
}
}
The JSON object represents a "Car" entity with various attributes such as Make, Model, Year, Color, Engine, and Features.
The "Engine" field is an embedded object with details such as Type and Displacement.
The "Features" field is an array containing various features or options available in the car.
JSON provides a structured way to represent data, and it's commonly used in various applications and data exchange scenarios due to its lightweight and easy-to-read format.
Handling JSON in UiPath
From activities panel » Programming » JSON
There are two different activities used to handle the Json Data in UiPath.
Deserialize JSON for JSON Object.
Deserialize JSON Array for any JSON arrays.
Deserialize JSON Activity
It will Deserialize our JSON string to object strings. Once deserialized, you can access different elements or fields within the deserialized object, depending on its structure, to extract information and perform various actions.
Example of Getting Values from Json Object:
You can get the values by using assign activities.
For Example,
We can get FirstName by UserData ("firstname").ToString keeping string as the DataType.
Deserialize JSON Array Activity
This activity deserializes JSON string to Array object, JSON Arrays are surrounded by square brackets.
How to get values from a JArray?
Get items by index. - jsonArrayData.Item(1) will return Toyota.
Task
Here will see how to get the data from API endpoint using automation.
Sample API endpoint https://randomuser.me/api
Create the new Process >> Install the Uipath.WebAPI.activities and start the automation.
Within squence drag and drop the HTTP Request.
Create the Argument and pass the Input as an API endpoint.
In Configuration give the end point to be the EndpointVariable argument.
Request method: GET ,
Response: ANY or JSON,
Then click Ok.
In the Output Panel assign the following variables:
Response Content that is our expected output data from the API endpoint,
Response status variable, it will be helpful to track the status of our API endpoint.
Then drop the Deserialize Json Activity and provide the HTTP Response content as the input, we will get the ouput as a JsonObject.
Json Object data variable: Newtonsoft.Json.Linq.JObeject
Then get required data from Json object using assign activity.
The Response Json object as a combination of both json and JArray, We can extract the complex json as follows.
· Title - UserData("results").item(0)("name")("title").ToString
· FirstName - UserData("results").item(0)("name")("first").ToString
· LastName - UserData("results").item(0)("name")("last").ToString
· City - UserData("results").item(0)("city").ToString
After data assigned ,we can use these data as per our needs, writing in an excel or to store it in a DB etc..
Conclusion
APIs allow UiPath robots to access data from various sources such as web services, databases, cloud platforms, and other software applications. This data can be used, processed, and manipulated in automated workflows. Integrating APIs expands the capabilities of UiPath robots by leveraging functionalities provided by external systems. So, if possible don’t miss the API Integration in your Project for Data Exchange.
Kowsalya S
RPA Engineer
Chisquare Labs, Kochi
Comments