Application Programming Interfaces (APIs) allow different software systems to communicate with each other. UiPath is a leading robotic process automation (RPA) platform that can be used to automate interactions with APIs. This allows you to leverage APIs in your automation workflows to connect systems, extract data, and more.
In this comprehensive guide, we will cover everything you need to know about calling APIs with UiPath. We will start with the basics of APIs and UiPath, then dive into step-by-step instructions and examples for calling REST and SOAP APIs. We will also provide tips and best practices for error handling, authentication, managing dependencies, and more. By the end, you will have the knowledge to start integrating APIs into your UiPath automations.
Contents
- What is an API?
- Benefits of Using APIs in RPA
- Introduction to UiPath
- UiPath API Capabilities
- Calling REST APIs
- Calling SOAP APIs
- Best Practices
- Managing Dependencies
- Authentication and Security
- Error and Exception Handling
- Conclusion
What is an API?
API stands for Application Programming Interface. It is a set of definitions, protocols, and tools for building software applications. An API specifies how different software components should interact with each other. This allows programs to communicate with each other without needing to know how they are implemented underneath.
APIs allow you to leverage functionality and data from other applications. For example, the Twitter API allows you to pull data from Twitter, while the Google Maps API lets you embed Google Maps into your application. APIs are everywhere and power most major applications today.
There are different types of APIs:
- REST APIs – REST (Representational State Transfer) is a software architectural style for APIs. REST APIs use HTTP requests like GET, POST, PUT, and DELETE to access and manipulate data.
- SOAP APIs – SOAP (Simple Object Access Protocol) is a protocol for exchanging structured information via APIs. SOAP uses XML information for requests and responses.
- Webhooks – Webhooks allow apps to provide other applications with real-time information via HTTPS callbacks.
- API Gateways – API gateways sit between clients and backends. They act as a reverse proxy to accept all API calls.
In this guide, we will focus specifically on calling REST and SOAP APIs with UiPath.
Benefits of Using APIs in RPA
Here are some of the key benefits of using APIs in robotic process automation:
- Connectivity – APIs allow RPA bots to integrate and exchange data with external apps and systems. This improves connectivity in your processes.
- Efficiency – APIs enable RPA bots to work faster by providing direct access to data and functionality from back-end systems.
- Maintainability – API connections abstract away the UI layer. This makes automation more maintainable as UI changes don’t break API connectivity.
- Scalability – APIs make it easier to scale automations across multiple interfaces and environments.
- Code reuse – API calls and workflows can be reused across multiple processes to prevent rework.
- Rich data – APIs allow access to richer, more structured data from systems compared to screen scraping.
Overall, APIs make RPA bots smarter, faster, and more efficient by giving them direct access to application data and functions.
Introduction to UiPath
Before we dive into calling APIs, let’s provide a quick overview of UiPath for those unfamiliar with the platform.
UiPath is a leading robotic process automation (RPA) tool. It uses software bots to automate repetitive, rules-based tasks. UiPath provides a visual workflow designer for building automation sequences using drag-and-drop activities.
Some key capabilities and components of UiPath include:
- Recording – UiPath bots can record user actions and turn them into automations.
- Selectors – Advanced computer vision technology that identifies UI elements.
- IDE – Integrated development environment for editing and debugging automations.
- Orchestrator – Web application for scheduling, monitoring, and managing robots.
- Activities – Reusable building blocks for automations like clicks, typing, reading data, etc.
UiPath activities are visual blocks that represent actions the bot can take. There are built-in activities for common functions, as well as hundreds of additional activities in packages and frameworks. This includes activities for calling APIs.
UiPath API Capabilities
UiPath provides a number of ways to work with APIs:
- HTTP Requests – For calling REST APIs using the HTTP Request and HTTP Response activities.
- SOAP – For calling SOAP web services using the SOAP activities.
- API Calls – A library of pre-built activities for common APIs like SharePoint, SAP, and Salesforce.
- .NET – Ability to call .NET code and libraries from automations.
In this guide, we will focus on the core HTTP Request and SOAP activities. The HTTP Request activity can be used to call any REST API. The SOAP activity is used for SOAP-based web services.
Now let’s look at how to call REST and SOAP APIs in UiPath step-by-step.
Calling REST APIs
REST (Representational State Transfer) is the most common API design pattern today. REST APIs follow a simple set of conventions and use HTTP requests like GET, POST, PUT, and DELETE to access and manipulate data.
Here is how to call REST APIs with UiPath:
1. Add HTTP Request Activity
Drag the HTTP Request activity onto your workflow where you want to make the API call.
2. Configure the URL and Method
In the HTTP Request activity, set the URL field to the API endpoint URL you want to call.
Select the appropriate HTTP method like GET, POST, PUT etc. based on the API documentation.
3. Add Headers
Most APIs require you to set a header for the Content-Type. For JSON APIs, this is typically application/json. Add any other required headers.
4. Add Body
For POST/PUT requests, add a JSON body payload if required by the API. This field supports string interpolation if you need to dynamically set values.
5. Output Response
Use the Response property to output the full API response object after execution. You can extract data from here in subsequent steps.
6. Handle Status Codes
Use an If activity after the request to check the StatusCode property. Handle different status codes like 400, 500 errors appropriately.
That covers the basics of calling REST APIs with UiPath. Now let’s walk through a full example.
Example: Call JSONPlaceholder API
JSONPlaceholder provides a sample REST API for testing. We will use it to demonstrate a GET request in UiPath.
The endpoints are:
- GET /posts
- GET /posts/{id}
Let’s call the /posts endpoint to get a list of posts.
- Add an HTTP Request activity
- Set URL to https://jsonplaceholder.typicode.com/posts
- Set Method = GET
- Add a Header: Content-Type = application/json
- Leave Body empty
- Output Response to a variable posts
After execution, the posts variable will contain a JSON array of posts. We can extract data or manipulate this response in subsequent steps.
We can add error handling for situations like the API being unreachable:
If (posts.StatusCode == 200) Then // Process data Else If (posts.StatusCode == 404) Then // API not found error Else // Unhandled error End If
This is the core approach for calling any REST API with UiPath. The same principles apply whether it is a public API or an internal API hosted in your environment.
Calling SOAP APIs
SOAP (Simple Object Access Protocol) is a messaging protocol for exchanging structured data between systems using XML. It provides a standard way to implement web services.
Though REST APIs are more common today, you may still need to connect to SOAP services from UiPath. Here are the steps to call a SOAP web service:
1. Add SOAP Activity
Drag the SOAP activity onto your workflow where you want to make the web service call.
2. Configure Service and Method
Enter the WSDL URL for the SOAP service in the WSDL field. This provides the service definition.
Select the Operation you want to call from the dropdown.
3. Map Input Parameters
Expand Input, then map any required input variables for the service operation.
4. Handle Output Values
Access and process output values from the SOAP response using the Output section.
5. Manage SOAP Faults
Handle SOAP faults and error codes using If activities on the FaultCode output property.
Let’s look at a quick example.
Example: Call Public Math Web Service
We will use a demo Math web service hosted at:
http://www.dneonline.com/calculator.asmx
It contains operations like Add, Subtract, Multiply etc. We will call the Add method.
- Add SOAP activity
- Set WSDL URL to the above endpoint
- Select Operation = Add
- Map Input intA = 10 and intB = 20
- Output Result to a variable sum
After execution, sum will contain the result of adding 10 + 20. We can process the output in subsequent steps.
To handle faults:
If (SOAP.FaultCode == "Server") Then // Service error End If
This demonstrates the overall process for calling any SOAP web service with UiPath.
Best Practices
Here are some best practices to follow when working with APIs in your UiPath automations:
Treat APIs as Separate Processes
Break down API interactions into their own workflows or processes. This improves reusability and encapuslation.
Use Logging
Log API requests, responses, and errors to help debug issues faster.
Handle Errors
Have clear error handling for HTTP status codes and SOAP faults. Don’t ignore errors.
Limit Calls
Avoid calling APIs in tight loops as it can overload them. Cache data if needed.
Monitor Performance
Monitor API response times to catch performance issues early.
Document Everything
Document API endpoints, sample requests/responses, meanings of status codes, etc.
Managing Dependencies
When calling third-party APIs, you need to manage the external dependency in your automation. Here are some tips:
- Reference APIs using NuGet packages when possible for easier upgrade management.
- Watch for API updates and deprecated endpoints.
- Limit external couplings and isolate API calls into separate workflows.
- Use API design patterns like gateway and facades if you own the APIs.
If a called API changes, the best practice is to contain the impact by modifying just the workflow or processes that contain the API activities. The more you decouple your automation from specific API dependencies, the easier it is to maintain and upgrade.
Authentication and Security
Most real-world APIs require authentication and have security considerations:
- API Keys – Pass API keys via request headers. Don’t hardcode them.
- OAuth – Implement OAuth authorization flows to generate access tokens.
- Basic Auth – Encode credentials into the Authorization header using Base64 encoding.
- Certificates – Call APIs over HTTPS. Use certificate activities if required.
- Sensitive data – Encrypt any sensitive data. Transmit over HTTPS.
Make sure to follow API security best practices. Never hardcode credentials or sensitive data. Store them in secured config files or credential stores instead. Use encryption and HTTPS wherever required.
Error and Exception Handling
Robust error handling is critical when interacting with external APIs:
- Always check HTTP status codes – Anything other than 200 range is an error.
- Check for and handle API errors like invalid requests, authentication failures, rate limiting, etc.
- Handle network failures and timeouts – API server could be down.
- For SOAP, check and process SOAP faults.
- Use Try Catch blocks and graceful error handling to avoid workflow failures.
- Log errors with context – API called, inputs, error response, etc.
Don’t ignore errors. They need to be handled appropriately or reported clearly to the user. Use logging and custom exceptions to add contextual information for diagnosing API issues faster.
Conclusion
This covers the end-to-end process for calling REST and SOAP APIs with UiPath. The key takeaways are:
- Use HTTP Request for REST APIs and SOAP activity for SOAP web services.
- Follow API documentation for correct endpoint URLs, parameters, methods.
- Output response objects for retrieving API results and status codes.
- Implement robust error handling with status codes and exceptions.
- Apply best practices like security, logging, external dependencies.
APIs enable UiPath robots to integrate tightly with back-end systems. This unlocks many more use cases for intelligent process automation. By mastering API integration with UiPath, you gain a critical skill to automate complex end-to-end processes across applications.