API Tokens
Manage API tokens in the sandbox.
Get listing of current Public API tokens
import asyncio
from ptsandbox import Sandbox, SandboxKey
async def main():
sandbox = Sandbox(...)
await sandbox.ui.authorize()
tokens = await sandbox.ui.get_api_tokens()
print(tokens)
asyncio.run(main())
ptsandbox.sandbox.ui._tokens.TokensMixin.get_api_tokens
async
Get listing of current Public API tokens
Returns:
-
SandboxTokensResponse–A model with information about all tokens
Raises:
-
SandboxException–if not authorized or token refresh fails
-
ClientResponseError–if the server returns an error status
-
ClientError–on connection or transport errors
-
ValidationError–if the response body does not match the expected model
Create a new Public API token
import asyncio
from ptsandbox import Sandbox, SandboxKey
from ptsandbox.models import TokenPermissions
async def main():
sandbox = Sandbox(...)
await sandbox.ui.authorize()
token = await sandbox.ui.create_api_token(
name="test-token",
permissions=[
TokenPermissions.SCAN_WITH_EXTENDED_SETTINGS,
TokenPermissions.SCAN_WITH_PREDEFINED_SETTINGS,
],
comment="test-comment",
)
print(token)
asyncio.run(main())
ptsandbox.sandbox.ui._tokens.TokensMixin.create_api_token
async
create_api_token(
name: str,
permissions: list[TokenPermissions],
comment: str = "",
) -> SandboxCreateTokenResponse
Create a new Public API token
Parameters:
-
name(str) –token name
-
permissions(list[TokenPermissions]) –permissions for the token
-
comment(str, default:'') –additional information about the token
Returns:
-
SandboxCreateTokenResponse–A model with information about the created token
Raises:
-
SandboxException–if not authorized or token refresh fails
-
ClientResponseError–if the server returns an error status
-
ClientError–on connection or transport errors
-
ValidationError–if the response body does not match the expected model
Delete the Public API token
import asyncio
from ptsandbox import Sandbox, SandboxKey
async def main():
sandbox = Sandbox(...)
await sandbox.ui.authorize()
await sandbox.ui.delete_api_token(token_id=1337)
asyncio.run(main())
ptsandbox.sandbox.ui._tokens.TokensMixin.delete_api_token
async
Delete the Public API token
Parameters:
-
token_id(int) –id of the PublicAPI token in the database
Raises:
-
SandboxException–if not authorized or token refresh fails
-
ClientResponseError–if the server returns an error status
-
ClientError–on connection or transport errors