Skip to content

Commit a80003f

Browse files
authored
Merge pull request #644 from UiPath/release/auth
2 parents 9165712 + d4db38d commit a80003f

24 files changed

+2201
-516
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.80"
3+
version = "2.1.81"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UIPATH_CLIENT_SECRET=
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# UiPath Coded Agent: Asset Value Checker
2+
3+
This project demonstrates how to create a Python-based UiPath Coded Agent that connects as an External Application to UiPath Orchestrator, retrieves an asset, and validates its IntValue against custom rules.
4+
5+
## Overview
6+
7+
The agent uses the UiPath Python SDK to:
8+
9+
* Connect to UiPath Orchestrator as an external application
10+
* Authenticate via the Client Credentials flow (Client ID + Client Secret)
11+
* Retrieve a specific asset from a given folder
12+
* Check whether the asset has an integer value and validate it against a range (100–1000)
13+
* Return a descriptive message with the validation result
14+
15+
## Prerequisites
16+
17+
* [UV package manager](https://docs.astral.sh/uv/) installed
18+
* UiPath Orchestrator access
19+
* An External Application configured in UiPath with the `OR.Assets` scope
20+
21+
You can learn how to create and setup your own External Application from the [UiPath documentation](https://docs.uipath.com/automation-cloud/automation-cloud/latest/admin-guide/managing-external-applications).
22+
23+
## Setup
24+
25+
### Step 1: Create and Activate Virtual Environment
26+
27+
```bash
28+
uv venv
29+
```
30+
31+
Activate the virtual environment:
32+
- **Windows**: `.venv\Scripts\activate`
33+
- **Linux/Mac**: `source .venv/bin/activate`
34+
35+
### Step 2: Install Dependencies
36+
37+
```bash
38+
uv sync
39+
```
40+
41+
### Step 3: Configure the Application
42+
43+
1. **Edit `main.py`** (lines 13, 16) and replace the placeholder values:
44+
- `UIPATH_CLIENT_ID`: Replace `"EXTERNAL_APP_CLIENT_ID_HERE"` with your External Application's Client ID
45+
- `UIPATH_URL`: Replace `"base_url"` with your Orchestrator URL (e.g., `"https://cloud.uipath.com/your_org/your_tenant"`)
46+
47+
2. **Set Environment Variables**
48+
49+
Create a `.env` file in the project directory or set the environment variable:
50+
```bash
51+
UIPATH_CLIENT_SECRET=your-client-secret-here
52+
```
53+
54+
### Step 4: Initialize the Agent
55+
56+
```bash
57+
uv run uipath init
58+
```
59+
60+
### Step 5: Prepare Input Data
61+
62+
Format your `input.json` file with the following structure:
63+
64+
```json
65+
{
66+
"asset_name": "test-asset",
67+
"folder_path": "TestFolder"
68+
}
69+
```
70+
71+
**Input Parameters:**
72+
- `asset_name`: The name of the UiPath asset to validate
73+
- `folder_path`: The folder path in Orchestrator where the asset is located
74+
75+
### Step 6: Run the Agent
76+
77+
Execute the agent locally:
78+
79+
```bash
80+
uipath run --input-file input.json
81+
```
82+
83+
## How It Works
84+
85+
When this agent runs, it will:
86+
87+
1. Load input values (`asset_name` and `folder_path`)
88+
2. Connect to Orchestrator using Client Credentials authentication
89+
3. Retrieve the specified asset from the given folder
90+
4. Validate the asset's IntValue against the allowed range (100–1000)
91+
5. Return a descriptive message with the validation result
92+
93+
**Possible Outputs:**
94+
- "Asset not found." — Asset doesn't exist
95+
- "Asset does not have an IntValue." — Asset exists but has no integer value
96+
- "Asset '<name>' has a valid IntValue: <value>" — IntValue is within range
97+
- "Asset '<name>' has an out-of-range IntValue: <value>" — IntValue is outside range
98+
99+
## Publish Your Coded Agent
100+
101+
Once tested locally, publish your agent to Orchestrator:
102+
103+
1. Pack the agent:
104+
```bash
105+
uipath pack
106+
```
107+
108+
2. Publish to Orchestrator:
109+
```bash
110+
uipath publish
111+
```
112+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"asset_name": "test-asset",
3+
"folder_path": "TestFolder"
4+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import dataclasses
2+
import dotenv
3+
import logging
4+
import os
5+
6+
from typing import Optional
7+
from uipath import UiPath
8+
from uipath.tracing import traced
9+
10+
dotenv.load_dotenv()
11+
logger = logging.getLogger(__name__)
12+
13+
UIPATH_CLIENT_ID = "EXTERNAL_APP_CLIENT_ID_HERE"
14+
UIPATH_CLIENT_SECRET = os.getenv("UIPATH_CLIENT_SECRET")
15+
UIPATH_SCOPE = "OR.Assets"
16+
UIPATH_URL = "base_url"
17+
18+
uipath = UiPath(
19+
client_id=UIPATH_CLIENT_ID,
20+
client_secret=UIPATH_CLIENT_SECRET,
21+
scope=UIPATH_SCOPE,
22+
base_url=UIPATH_URL
23+
)
24+
25+
@dataclasses.dataclass
26+
class AgentInput:
27+
"""Input data structure for the UiPath agent.
28+
29+
Attributes:
30+
asset_name (str): The name of the UiPath asset.
31+
folder_path (str): The folder path where the asset is located.
32+
"""
33+
asset_name: str
34+
folder_path: str
35+
36+
def get_asset(name: str, folder_path: str) -> Optional[object]:
37+
"""Retrieve an asset from UiPath.
38+
39+
Args:
40+
name (str): The asset name.
41+
folder_path (str): The UiPath folder path.
42+
43+
Returns:
44+
Optional[object]: The asset object if found, else None.
45+
"""
46+
return uipath.assets.retrieve(name=name, folder_path=folder_path)
47+
48+
def check_asset(asset: object) -> str:
49+
"""Check if an asset's IntValue is within a valid range.
50+
51+
Args:
52+
asset (object): The asset object.
53+
54+
Returns:
55+
str: Result message depending on asset state.
56+
"""
57+
if asset is None:
58+
return "Asset not found."
59+
60+
int_value = getattr(asset, "int_value", None)
61+
if int_value is None:
62+
return "Asset does not have an IntValue."
63+
64+
if 100 <= int_value <= 1000:
65+
return f"Asset '{asset.name}' has a valid IntValue: {int_value}"
66+
else:
67+
return f"Asset '{asset.name}' has an out-of-range IntValue: {int_value}"
68+
69+
@traced()
70+
def main(input: AgentInput) -> str:
71+
"""Main entry point for the agent.
72+
73+
Args:
74+
input (AgentInput): The input containing asset details.
75+
76+
Returns:
77+
str: Message with the result of the asset check.
78+
"""
79+
asset = get_asset(input.asset_name, input.folder_path)
80+
return check_asset(asset)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "asset-checker-agent"
3+
version = "0.0.1"
4+
description = "UiPath agent to validate asset values via External Application integration with Orchestrator."
5+
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
6+
dependencies = [
7+
"uipath>=2.1.45",
8+
]
9+
requires-python = ">=3.10"

0 commit comments

Comments
 (0)