Utility modules provide common functionality available to all OpalScript types. These modules help you query Opal’s data and make informed decisions.Documentation Index
Fetch the complete documentation index at: https://docs.opal.dev/llms.txt
Use this file to discover all available pages before exploring further.
Query Opal’s access graph
accesslib Module
Theaccesslib module provides functions to query Opal’s access graph. Use it to check existing permissions when making automation decisions.
accesslib.check_access(principal_id, entity_id, [access_level_remote_id]) checks whether a principal (user or group) currently has access to an entity (resource or group).
The ID of the user or group to check
The ID of the resource or group to check access to
Filter by specific access level (e.g.,
"admin", "viewer")True if access exists, False otherwise
Send notifications
notificationslib Module
Thenotificationslib module provides functions to send notifications to users, admins, and owners from within a script.
Notify a user
notificationslib.notify_user(user_id, title, body) sends a notification to a specific user via email and Slack (if configured).
The ID of the user to notify
Notification title
Notification body
True if the notification was sent successfully, False otherwise
Notify all admins
notificationslib.notify_admins(title, body) sends a notification to all Opal admins.
Notification title
Notification body
True if the notification was sent successfully, False otherwise
Notify an owner
notificationslib.notify_owner(owner_id, title, body) sends a notification to an owner. If the owner has a Slack message channel configured, the notification is sent to that channel only. Otherwise it is sent to all individual users in the owner.
The ID of the owner to notify
Notification title
Notification body
True if the notification was sent successfully, False otherwise
Manage support tickets
ticketslib Module
Theticketslib module provides functions to create, retrieve, comment on, and close tickets in connected ticket providers. Use it to automatically file or update tickets as part of your access automation workflows.
Supported providers: Jira, Linear, ServiceNow, Notion, FreshService, and Shortcut. Only providers that are installed and connected to your Opal organization are available at runtime.
Tickets created via OpalScript are independent of tickets created via ticket propagation. If ticket propagation is also enabled, a separate ticket will be created after the request is approved. Creating a ticket via OpalScript does not replace or affect that flow.
Access a provider
ticketslib.providers.<PROVIDER> exposes the ticket providers installed for your organization as a namespace. Reference a provider by name to pass it to other ticketslib functions.
Available provider names: JIRA, LINEAR, SERVICE_NOW, NOTION, FRESH_SERVICE, SHORTCUT
List projects
ticketslib.list_projects(provider) returns all projects available on the given provider.
A provider from
ticketslib.providers"ENG"). Each value is a ticket_project object:
| Attribute | Type | Description |
|---|---|---|
key | string | The project’s key in the remote provider (e.g. "ENG") |
name | string | The project’s display name |
provider | string | The provider name |
Create a ticket
ticketslib.create_ticket(project, title, description) creates a new ticket on the remote provider and stores it in Opal.
A project object returned by
ticketslib.list_projectsThe title or summary of the ticket
The description or body of the ticket
ticket object:
| Attribute | Type | Description |
|---|---|---|
url | string | A URL to view the ticket in the provider’s UI |
identifier | string | The human-readable ticket identifier (e.g. "ENG-42") |
remote_id | string | The ticket’s ID in the remote provider |
provider | string | The provider name |
status | string | "ACTIVE", "CLOSED", or "NOT_FOUND" |
Get a ticket
ticketslib.get_ticket(provider, remote_ticket_id) fetches an existing ticket from the remote provider by its identifier.
A provider from
ticketslib.providersThe ticket’s identifier in the remote provider (e.g.
"ENG-42")ticket object with the same attributes as returned by create_ticket above.
Comment on a ticket
ticketslib.comment_ticket(provider, remote_ticket_id, comment) adds a comment to an existing ticket. Does not change the ticket’s status.
A provider from
ticketslib.providersThe ticket’s identifier in the remote provider (e.g.
"ENG-42")The text of the comment to add
None
Close a ticket
ticketslib.close_ticket(provider, remote_ticket_id, [comment]) closes an existing ticket on the remote provider and updates its stored status in Opal to CLOSED. No-op if the ticket is already closed.
A provider from
ticketslib.providersThe ticket’s identifier in the remote provider (e.g.
"ENG-42")An optional closing comment to add before closing
None
Query assets
assetlib Module
Theassetlib module provides functions to look up the risk sensitivity classification of resources and groups, and to query historical access requests for them.
Request history lookups return a dictionary keyed by stringified request UUID. The values are request objects with the same shape as the one returned by context.get_request(). If no requests match, the dictionary is empty. Looking up a missing ID raises a key error, so guard with if request_id in requests: when needed. Pass empty strings ("") to skip any optional string argument.
Results are ordered by (updated_at DESC, id DESC) and filtered to the caller’s organization. The returned value also exposes a next_cursor attribute — an opaque string to pass back as the cursor argument on the next call. It is "" when there are no further pages. When both cursor and requests_per_page are omitted, every match is returned in a single call and next_cursor is "".
Get resource risk sensitivity
assetlib.get_resource_risk_sensitivity(resource_id) returns the risk sensitivity level of a resource.
The ID of the resource
"UNKNOWN", "NONE", "LOW", "MEDIUM", "HIGH", or "CRITICAL"
Get group risk sensitivity
assetlib.get_group_risk_sensitivity(group_id) returns the risk sensitivity level of a group.
The ID of the group
"UNKNOWN", "NONE", "LOW", "MEDIUM", "HIGH", or "CRITICAL"
Get requests for a resource
assetlib.get_requests_for_resource(resource_id, [user_id], [request_status], [cursor], [requests_per_page]) returns every request whose requested_resources includes resource_id. The optional user_id filter narrows to requests submitted by that user (requester_id), not the target user.
A single request that asked for multiple resources will appear in queries for each one.
The resource being queried
Narrow to requests submitted by this user. Pass
"" to skipOne of
"PENDING", "APPROVED", "DENIED", "CANCELED". Pass "" to skipOpaque page cursor from a previous call’s
next_cursor. Pass "" for the first pagePage size. Must be positive. Omit to return all matches in a single call
next_cursor attribute for pagination. See Request object for the value shape.
Get requests for a group
assetlib.get_requests_for_group(group_id, [user_id], [request_status], [cursor], [requests_per_page]) returns every request whose requested_groups includes group_id. This filters on what was asked for — a request with target_group_id = X but no X in requested_groups does not match.
The group being queried
Narrow to requests submitted by this user. Pass
"" to skipOne of
"PENDING", "APPROVED", "DENIED", "CANCELED". Pass "" to skipOpaque page cursor from a previous call’s
next_cursor. Pass "" for the first pagePage size. Must be positive. Omit to return all matches in a single call
next_cursor attribute for pagination. See Request object for the value shape.
Query user request history
userlib Module
Theuserlib module provides functions to query Opal’s request history for a user.
userlib.get_requests(user_id, [request_status], [cursor], [requests_per_page]) returns every request where the given user is either the requester (submitted it) or the target user (recipient of the access). A self-request (requester == target) appears once.
The ID of the user
One of
"PENDING", "APPROVED", "DENIED", "CANCELED". Pass "" to skipOpaque page cursor from a previous call’s
next_cursor. Pass "" for the first pagePage size. Must be positive. Omit to return all matches in a single call
next_cursor attribute for pagination. See Request object for the value shape. Looking up a missing ID raises a key error — guard with if request_id in requests: when needed.
Work with time
timelib Module
Thetimelib module provides functions to work with Unix timestamps (seconds since epoch) and time intervals for access duration validation and temporal logic.
Get current time
timelib.now() returns the current Unix timestamp (seconds since epoch).
An integer representing the current time as a Unix timestamp
Convert timestamp to string
timelib.from_unix(timestamp) converts a Unix timestamp to an RFC3339 formatted string in UTC (e.g., 2024-01-15T10:30:45Z).
Unix timestamp to convert
Compare timestamps
timelib.is_before(timestamp1, timestamp2) checks if the first timestamp is before the second.
timelib.is_after(timestamp1, timestamp2) checks if the first timestamp is after the second.
First timestamp
Second timestamp
True or False
Calculate time differences
timelib.seconds_since(timestamp1, timestamp2) returns the number of seconds between two timestamps (positive if timestamp1 is after timestamp2).
First timestamp
Second timestamp
Convert time intervals to seconds
Usetimelib.minutes(n), timelib.hours(n), and timelib.days(n) to convert human-readable time intervals to seconds. This is useful for time comparisons and avoids hardcoding magic numbers.
Number of time units
Important notes
- Timestamps are UTC only: All
timelibfunctions work in UTC. There is no timezone conversion support. - Second precision: Timestamps have second-level precision. Sub-second differences are not available.
- No test mode: OpalScript automations execute on real access requests. Test your logic with low-risk parameters first.
- Review before deploying: All OpalScript automations should be reviewed by a human before deployment to catch logic errors.
Look up entity information
entitylib Module
Theentitylib module provides functions to look up users, groups, and resources by their IDs. Use it to access entity properties and tags when making automation decisions.
Get a user
entitylib.get_user(user_id) retrieves a user by their UUID.
The ID of the user to fetch
| Attribute | Type | Description |
|---|---|---|
id | string | The user’s UUID |
position | string | The user’s job position |
team | string or None | The user’s team name |
manager_id | string or None | The UUID of the user’s manager |
is_service_user | bool | Whether the user is a service user |
is_deleted | bool | Whether the user is deleted |
tags | dict | Tags assigned to the user, keyed by tag key |
Get a group
entitylib.get_group(group_id) retrieves a group by its UUID.
The ID of the group to fetch
| Attribute | Type | Description |
|---|---|---|
id | string | The group’s UUID |
name | string | The group’s name |
description | string | The group’s description |
group_type | string | The type of group (e.g., "STANDARD") |
is_deleted | bool | Whether the group is deleted |
tags | dict | Tags assigned to the group, keyed by tag key |
Get a resource
entitylib.get_resource(resource_id) retrieves a resource by its UUID.
The ID of the resource to fetch
| Attribute | Type | Description |
|---|---|---|
id | string | The resource’s UUID |
name | string | The resource’s name |
description | string | The resource’s description |
resource_type | string | The type of resource (e.g., "GITHUB") |
is_deleted | bool | Whether the resource is deleted |
tags | dict | Tags assigned to the resource, keyed by tag key |
Tags
All entity objects include atags dictionary that maps tag keys to string values (None if the tag has no value).

