access_token
access_token ¶
Access token routes — CRUD for Domo access tokens.
Wraps the /api/data/v1/accesstokens endpoints: access tokens are
created in Admin → Authentication → Access tokens, authenticate API
calls on behalf of a specific user, and carry a name, owner, and
expiration date. Domo docs:
Access Tokens KB.
A representative example of the routes-layer pattern (see the
crew_dcs.routes package docstring): each public function maps to one
endpoint operation, calls crew_dcs.client.get_data.get_data(), raises
a module-local RouteError subclass when res.is_success is false,
and otherwise returns the payload as Domo sent it. The one concession
to convenience: get_access_tokens converts each token's Unix
expires timestamp to a datetime, and revoke_access_token returns
a plain confirmation string.
Functions:
| Name | Description |
|---|---|
get_access_tokens |
Retrieve all access tokens for the authenticated instance |
get_access_token_by_id |
Retrieve a specific access token by ID |
generate_access_token |
Create a new access token for a user |
revoke_access_token |
Revoke an existing access token |
generate_expiration_unixtimestamp |
Utility function for timestamp generation |
Exception Classes
AccessToken_GET_Error: Raised when token retrieval fails SearchAccessTokenNotFoundError: Raised when token search returns no results AccessToken_CRUD_Error: Raised when token create/update/delete operations fail
AccessToken_CRUD_Error ¶
AccessToken_CRUD_Error(
operation: str,
entity_id: str | None = None,
res: ResponseGetData | None = None,
message: str | None = None,
**kwargs,
)
Bases: RouteError
Raised when access token create, update, or delete operations fail.
This exception is used for failures during token generation, modification, or revocation operations.
Source code in src/crew_dcs/routes/access_token.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
AccessToken_GET_Error ¶
AccessToken_GET_Error(
entity_id: str | None = None,
res: ResponseGetData | None = None,
message: str | None = None,
**kwargs,
)
Bases: RouteError
Raised when access token retrieval operations fail.
This exception is used for failures during GET operations on access tokens, including API errors and unexpected response formats.
Source code in src/crew_dcs/routes/access_token.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
SearchAccessTokenNotFoundError ¶
SearchAccessTokenNotFoundError(
search_criteria: str,
res: ResponseGetData | None = None,
**kwargs,
)
Bases: RouteError
Raised when access token search operations return no results.
This exception is used when searching for specific access tokens that don't exist or when search criteria match no tokens.
Source code in src/crew_dcs/routes/access_token.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
generate_access_token
async
¶
generate_access_token(
auth: DomoAuth,
token_name: str,
user_id: int | str,
duration_in_days: int = 90,
return_raw: bool = False,
*,
context: RouteContext | None = None,
**context_kwargs,
) -> ResponseGetData
Generate a new access token for a user.
Creates a new access token with the specified name and expiration period for the given user ID. The token can be used for API authentication.
SECURITY: mints a token for ANY user_id using the CALLER's auth — this is
a sudo primitive. The minted token is a full Domo user credential, not
app-scoped: the holder can call the whole API as that user. Blast radius =
whatever that user's groups grant.
duration_in_days defaults to 90. Set it short for anything short-lived
(e.g. a browser-held session) and revoke explicitly — see
revoke_access_token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
DomoAuth
|
Authentication object containing instance and credentials |
required |
token_name
|
str
|
Descriptive name for the new access token |
required |
user_id
|
int | str
|
Unique identifier for the user who will own the token |
required |
duration_in_days
|
int
|
Number of days until token expires (default: 90) |
90
|
return_raw
|
bool
|
Return raw API response without processing |
False
|
context
|
RouteContext | None
|
RouteContext for request configuration |
None
|
Returns:
| Type | Description |
|---|---|
ResponseGetData
|
ResponseGetData object containing the generated token information |
Raises:
| Type | Description |
|---|---|
AccessToken_CRUD_Error
|
If token generation fails or user ID is invalid |
Example
token_response = await generate_access_token( ... auth, "API Integration Token", 12345, 30 ... ) token_value = token_response.response["token"] print(f"Generated token: {token_value}")
Endpoint
POST /data/v1/accesstokens
Called by
Source code in src/crew_dcs/routes/access_token.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
generate_expiration_unixtimestamp ¶
generate_expiration_unixtimestamp(
duration_in_days: int = 90,
) -> int
Generate Unix timestamp for access token expiration.
Creates a Unix timestamp (in milliseconds) for an expiration date that is the specified number of days from today.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration_in_days
|
int
|
Number of days from today for expiration (default: 90) |
90
|
Returns:
| Type | Description |
|---|---|
int
|
Unix timestamp in milliseconds for the expiration date |
Example
timestamp = generate_expiration_unixtimestamp(30) expiry_date = datetime.fromtimestamp(timestamp / 1000) print(f"Token expires on: {expiry_date}")
Source code in src/crew_dcs/routes/access_token.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
get_access_token_by_id
async
¶
get_access_token_by_id(
auth: DomoAuth,
access_token_id: int,
return_raw: bool = False,
*,
context: RouteContext | None = None,
**context_kwargs,
) -> ResponseGetData
Retrieve a specific access token by its ID.
Fetches details for a single access token identified by its unique ID. This function first retrieves all tokens and then filters to find the specific token requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
DomoAuth
|
Authentication object containing instance and credentials |
required |
access_token_id
|
int
|
Unique identifier for the access token to retrieve |
required |
return_raw
|
bool
|
Return raw API response without processing |
False
|
context
|
RouteContext | None
|
RouteContext for request configuration |
None
|
Returns:
| Type | Description |
|---|---|
ResponseGetData
|
ResponseGetData object containing the specific access token data |
Raises:
| Type | Description |
|---|---|
AccessToken_GET_Error
|
If token retrieval fails |
SearchAccessTokenNotFoundError: If no token with the specified ID exists
Example
token_response = await get_access_token_by_id(auth, 12345) token_data = token_response.response print(f"Token Name: {token_data['name']}")
Calls route
Called by
Source code in src/crew_dcs/routes/access_token.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
get_access_tokens
async
¶
get_access_tokens(
auth: DomoAuth,
return_raw: bool = False,
*,
context: RouteContext | None = None,
**context_kwargs,
) -> ResponseGetData
Retrieve all access tokens for the authenticated instance.
Fetches a list of all access tokens associated with the current Domo instance. Each token includes metadata such as name, owner, and expiration date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
DomoAuth
|
Authentication object containing instance and credentials |
required |
return_raw
|
bool
|
Return raw API response without processing |
False
|
context
|
RouteContext | None
|
RouteContext for request configuration |
None
|
Returns:
| Type | Description |
|---|---|
ResponseGetData
|
ResponseGetData object containing list of access tokens with converted |
ResponseGetData
|
expiration timestamps to datetime objects |
Raises:
| Type | Description |
|---|---|
AccessToken_GET_Error
|
If token retrieval fails or API returns an error |
Example
tokens_response = await get_access_tokens(auth) for token in tokens_response.response: ... print(f"Token: {token['name']}, Expires: {token['expires']}")
Endpoint
GET /data/v1/accesstokens
Called by
Source code in src/crew_dcs/routes/access_token.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
revoke_access_token
async
¶
revoke_access_token(
auth: DomoAuth,
access_token_id: int,
return_raw: bool = False,
*,
context: RouteContext | None = None,
**context_kwargs,
) -> ResponseGetData
Revoke an existing access token.
Permanently revokes an access token, making it immediately unusable for API authentication. This action cannot be undone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
DomoAuth
|
Authentication object containing instance and credentials |
required |
access_token_id
|
int
|
Unique identifier for the token to revoke |
required |
return_raw
|
bool
|
Return raw API response without processing |
False
|
context
|
RouteContext | None
|
RouteContext for request configuration |
None
|
Returns:
| Type | Description |
|---|---|
ResponseGetData
|
ResponseGetData object with confirmation message |
Raises:
| Type | Description |
|---|---|
AccessToken_CRUD_Error
|
If token revocation fails |
Example
response = await revoke_access_token(auth, 12345) print(response.response) # "access token 12345 revoked"
Endpoint
DELETE /data/v1/accesstokens/{}
Called by
Source code in src/crew_dcs/routes/access_token.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
See also¶
Domo Knowledge Base categories
- Administer Domo (users, groups, roles, grants, instance settings, activity log)