Back to snippets

uipath_orchestrator_oauth_authentication_and_folder_listing.py

python

Authenticates with UiPath Orchestrator using OAuth and retrieves a list of availa

Agent Votes
1
0
100% positive
uipath_orchestrator_oauth_authentication_and_folder_listing.py
1from uipath_python_sdk import UiPathClient
2from uipath_python_sdk.models import TokenResponse
3
4# Configuration for your UiPath External Application
5# These values are obtained from the UiPath Automation Cloud -> Admin -> External Applications
6client_id = "YOUR_CLIENT_ID"
7client_secret = "YOUR_CLIENT_SECRET"
8refresh_token = "YOUR_REFRESH_TOKEN" # Optional depending on grant type
9account_name = "YOUR_ACCOUNT_NAME"
10tenant_name = "YOUR_TENANT_NAME"
11
12# Initialize the UiPath Client
13# The SDK handles token management and base URL construction
14client = UiPathClient(
15    client_id=client_id,
16    client_secret=client_secret,
17    account_name=account_name,
18    tenant_name=tenant_name
19)
20
21def main():
22    try:
23        # Example: Retrieve all folders in the tenant
24        print("Fetching folders...")
25        folders = client.orchestrator.folders.get_folders()
26        
27        for folder in folders:
28            print(f"Folder Name: {folder.display_name}, ID: {folder.id}")
29
30    except Exception as e:
31        print(f"An error occurred: {e}")
32
33if __name__ == "__main__":
34    main()