URL Categories Configuration Object
Table of Contents
- Overview
- Core Methods
- URL Category Model Attributes
- Exceptions
- Basic Configuration
- Usage Examples
- Managing Configuration Changes
- Error Handling
- Best Practices
- Full Script Examples
- Related Models
Overview
The URLCategories
class provides functionality to manage URL category objects in Palo Alto Networks' Strata Cloud
Manager. This class inherits from BaseObject
and provides methods for creating, retrieving, updating, and deleting
custom URL categories that can be used in security policies and profiles.
Core Methods
Method | Description | Parameters | Return Type |
---|---|---|---|
create() |
Creates a new URL category | data: Dict[str, Any] |
URLCategoriesResponseModel |
get() |
Retrieves a category by ID | object_id: str |
URLCategoriesResponseModel |
update() |
Updates an existing category | profile: URLCategoriesUpdateModel |
URLCategoriesResponseModel |
delete() |
Deletes a category | object_id: str |
None |
list() |
Lists categories with filtering | folder: str , **filters |
List[URLCategoriesResponseModel] |
fetch() |
Gets category by name | name: str , folder: str |
URLCategoriesResponseModel |
URL Category Model Attributes
Attribute | Type | Required | Description |
---|---|---|---|
name |
str | Yes | Name of URL category |
id |
UUID | Yes* | Unique identifier (*response only) |
list |
List[str] | Yes | List of URLs or patterns |
type |
Enum | No | Category type (URL List/Category Match) |
description |
str | No | Category description |
folder |
str | Yes** | Folder location (**one container required) |
snippet |
str | Yes** | Snippet location (**one container required) |
device |
str | Yes** | Device location (**one container required) |
Exceptions
Exception | HTTP Code | Description |
---|---|---|
InvalidObjectError |
400 | Invalid category data or format |
MissingQueryParameterError |
400 | Missing required parameters |
NameNotUniqueError |
409 | Category name already exists |
ObjectNotPresentError |
404 | Category not found |
ReferenceNotZeroError |
409 | Category still referenced |
AuthenticationError |
401 | Authentication failed |
ServerError |
500 | Internal server error |
Basic Configuration
# Initialize clientclient = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id"
)
# Access URL categories directly through the client# No need to initialize a separate URLCategories object
Usage Examples
Creating URL Categories
"name": "blocked_sites",
"type": "URL List",
"list": ["example.com", "test.com"],
"description": "Blocked websites list",
"folder": "Texas"
}
# Create URL List category using the clienturl_list = client.url_category.create(url_list_config)
# Category Match configurationcategory_match_config = {
"name": "social_media",
"type": "Category Match",
"list": ["social-networking", "personal-sites-and-blogs"],
"description": "Social media categories",
"folder": "Texas"
}
# Create Category Match categorycategory_match = client.url_category.create(category_match_config)
Retrieving URL Categories
print(f"Found category: {category.name}")
# Get by IDcategory_by_id = client.url_category.get(category.id)
print(f"Retrieved category: {category_by_id.name}")
print(f"URL list: {category_by_id.list}")
Updating URL Categories
# Update URL listexisting_category.list.extend(["newsite.com", "anothersite.com"])
existing_category.description = "Updated blocked websites list"
# Perform updateupdated_category = client.url_category.update(existing_category)
Listing URL Categories
folder='Texas',
members=['example.com']
)
# Process resultsfor category in filtered_categories:
print(f"Name: {category.name}")
print(f"Type: {category.type}")
print(f"URLs: {category.list}")
# Define filter parameters as dictionarylist_params = {
"folder": "Texas",
"members": ["social-networking"]
}
# List with filters as kwargsfiltered_categories = client.url_category.list(**list_params)
Filtering Responses
The list()
method supports additional parameters to refine your query results even further. Alongside basic filters
(like types
, values
, and tags
), you can leverage the exact_match
, exclude_folders
, exclude_snippets
, and
exclude_devices
parameters to control which objects are included or excluded after the initial API response is fetched.
Parameters:
exact_match (bool)
: WhenTrue
, only objects defined exactly in the specified container (folder
,snippet
, ordevice
) are returned.exclude_folders (List[str])
: Provide a list of folder names to exclude.exclude_snippets (List[str])
: Provide a list of snippet values to exclude.exclude_devices (List[str])
: Provide a list of device values to exclude.
Examples:
folder='Texas',
exact_match=True
)
for app in exact_url_categories:
print(f"Exact match: {app.name} in {app.folder}")
# Exclude all url_categories from the 'All' folderno_all_url_categories = client.url_category.list(
folder='Texas',
exclude_folders=['All']
)
for app in no_all_url_categories:
assert app.folder != 'All'
print(f"Filtered out 'All': {app.name}")
# Exclude url_categories that come from 'default' snippetno_default_snippet = client.url_category.list(
folder='Texas',
exclude_snippets=['default']
)
for app in no_default_snippet:
assert app.snippet != 'default'
print(f"Filtered out 'default' snippet: {app.name}")
# Exclude url_categories associated with 'DeviceA'no_deviceA = client.url_category.list(
folder='Texas',
exclude_devices=['DeviceA']
)
for app in no_deviceA:
assert app.device != 'DeviceA'
print(f"Filtered out 'DeviceA': {app.name}")
# Combine exact_match with multiple exclusionscombined_filters = client.url_category.list(
folder='Texas',
exact_match=True,
exclude_folders=['All'],
exclude_snippets=['default'],
exclude_devices=['DeviceA']
)
for app in combined_filters:
print(f"Combined filters result: {app.name} in {app.folder}")
Controlling Pagination with max_limit
The SDK supports pagination through the max_limit
parameter, which defines how many objects are retrieved per API call. By default, max_limit
is set to 2500. The API itself imposes a maximum allowed value of 5000. If you set max_limit
higher than 5000, it will be capped to the API's maximum. The list()
method will continue to iterate through all objects until all results have been retrieved. Adjusting max_limit
can help manage retrieval performance and memory usage when working with large datasets.
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id",
url_categories_max_limit=4321
)
# Now when we call list(), it will use the specified max_limit for each request# while auto-paginating through all available objects.all_categories = client.url_category.list(folder='Texas')
# 'all_categories' contains all objects from 'Texas', fetched in chunks of up to 4321 at a time.
Deleting URL Categories
client.url_category.delete(category_id)
Managing Configuration Changes
Performing Commits
"folders": ["Texas"],
"description": "Updated URL categories",
"sync": True,
"timeout": 300 # 5 minute timeout
}
# Commit the changes directly using the clientresult = client.commit(**commit_params)
print(f"Commit job ID: {result.job_id}")
Monitoring Jobs
print(f"Job status: {job_status.data[0].status_str}")
# List recent jobs using the clientrecent_jobs = client.list_jobs(limit=10)
for job in recent_jobs.data:
print(f"Job {job.id}: {job.type_str} - {job.status_str}")
Error Handling
InvalidObjectError,
MissingQueryParameterError,
NameNotUniqueError,
ObjectNotPresentError,
ReferenceNotZeroError
)
try:
# Create category configuration
category_config = {
"name": "test_category",
"type": "URL List",
"list": ["example.com", "test.com"],
"folder": "Texas",
"description": "Test URL category"
}
# Create the category using the client
new_category = client.url_category.create(category_config)
# Commit changes using the client
result = client.commit(
folders=["Texas"],
description="Added test category",
sync=True
)
# Check job status using the client
status = client.get_job_status(result.job_id)
except InvalidObjectError as e:
print(f"Invalid category data: {e.message}")
except NameNotUniqueError as e:
print(f"Category name already exists: {e.message}")
except ObjectNotPresentError as e:
print(f"Category not found: {e.message}")
except ReferenceNotZeroError as e:
print(f"Category still in use: {e.message}")
except MissingQueryParameterError as e:
print(f"Missing parameter: {e.message}")
Best Practices
-
URL List Management
- Use descriptive category names
- Group related URLs together
- Validate URL patterns before adding
- Keep lists manageable in size
- Document category purposes
-
Container Management
- Always specify exactly one container (folder, snippet, or device)
- Use consistent container names
- Validate container existence
- Group related categories
-
Client Usage
- Use the unified client interface (
client.url_category
) for simpler code - Perform commits directly on the client (
client.commit()
) - Monitor jobs using client methods (
client.get_job_status()
,client.list_jobs()
) - Initialize the client once and reuse across different object types
- Use the unified client interface (
-
Category Types
- Choose appropriate type (URL List vs Category Match)
- Validate category match patterns
- Consider URL resolution impact
- Document type selection rationale
-
Performance
- Use appropriate pagination
- Cache frequently accessed categories
- Implement proper retry logic
- Monitor URL resolution times
-
Security
- Follow least privilege principle
- Validate input URLs
- Use secure connection settings
- Monitor category usage
Full Script Examples
Refer to the url_categories.py example.