ShortUrlsClient¶
Client for the Kibana Short URLs API.
Kibana URLs may be long and cumbersome; short URLs are much easier to remember and share. Short URLs are created by specifying a locator ID and locator parameters. When a short URL is resolved, the locator ID and locator parameters are used to redirect the user to the right Kibana page.
Note
All Short URL APIs are marked as technical preview in Kibana 9.4 and may change in future releases.
Short URLs are space-scoped saved objects: a short URL created in one space
is not visible from another space. Every method accepts an optional
space_id to target a specific space.
- class kibana._sync.client.short_urls.ShortUrlsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
NamespaceClientClient for the Kibana Short URLs API.
Kibana URLs may be long and cumbersome; short URLs are much easier to remember and share. Short URLs are created by specifying a locator ID and locator parameters. When a short URL is resolved, the locator ID and locator parameters are used to redirect the user to the right Kibana page.
All Short URL APIs are marked as Technical Preview in Kibana 9.4 and may change in future releases.
Short URLs are space-scoped saved objects: a short URL created in one space is not visible from another space. Every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import Kibana >>> client = Kibana("http://localhost:5601", api_key="...") >>> >>> # Create a short URL using the legacy short URL locator >>> created = client.short_urls.create( ... locator_id="LEGACY_SHORT_URL_LOCATOR", ... params={"url": "/app/dashboards"}, ... ) >>> slug = created.body["slug"] >>> >>> # Resolve it by slug, then delete it >>> resolved = client.short_urls.resolve(slug=slug) >>> client.short_urls.delete(id=resolved.body["id"])
Creating Short URLs
Create a short URL with the
create()method:from kibana import Kibana client = Kibana("http://localhost:5601", api_key="your_api_key") # Create a short URL using the legacy short URL locator created = client.short_urls.create( locator_id="LEGACY_SHORT_URL_LOCATOR", params={"url": "/app/dashboards"}, ) slug = created.body["slug"] short_url_id = created.body["id"] print(f"Short URL: http://localhost:5601/r/s/{slug}") # Ask Kibana for a human-readable slug instead of a random one readable = client.short_urls.create( locator_id="LEGACY_SHORT_URL_LOCATOR", params={"url": "/app/dashboards"}, human_readable_slug=True, )
Resolving and Retrieving Short URLs
# Resolve a short URL by its slug resolved = client.short_urls.resolve(slug=slug) print(resolved.body["locator"]) # Get a short URL by its ID short_url = client.short_urls.get(id=short_url_id)
Deleting Short URLs
client.short_urls.delete(id=short_url_id)
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the ShortUrlsClient.
- Parameters:
Example
>>> short_urls_client = ShortUrlsClient(kibana_client)
- create(*, locator_id, params, slug=None, human_readable_slug=None, space_id=None, validate_spaces=None)[source]¶
Create a short URL.
Technical preview in 9.4. Creates a Kibana short URL from a locator ID and its parameters. When the short URL is resolved, the locator redirects the user to the right Kibana page.
Warning: locator
paramsare not validated by Kibana, which allows you to pass arbitrary and ill-formed data into the API that can break Kibana. Make sure any data that you send to the API is properly formed.- Parameters:
locator_id (str) – The identifier for the locator (for example,
"LEGACY_SHORT_URL_LOCATOR"or"DASHBOARD_APP_LOCATOR").params (dict[str, Any]) – An object which contains all necessary parameters for the given locator to resolve to a Kibana location.
slug (str | None) – A custom short URL slug. The slug is the part of the short URL that identifies it. It may consist of latin alphabet letters, numbers, and
-._characters and must be between 3 and 255 characters long.human_readable_slug (bool | None) – When
slugis omitted and this is set to True, the API generates a random human-readable slug instead of a random short string.space_id (str | None) – Optional space ID to create the short URL in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
id: The identifier for the short URL
slug: The slug that resolves to this short URL
locator: The locator
id,versionandstateaccessCount / accessDate / createDate: usage metadata
- Return type:
ObjectApiResponse containing the created short URL
- Raises:
BadRequestError – If the request body is invalid (e.g. bad slug).
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> created = client.short_urls.create( ... locator_id="LEGACY_SHORT_URL_LOCATOR", ... params={"url": "/app/dashboards"}, ... slug="my-dashboards", ... ) >>> print(created.body["slug"]) my-dashboards
- get(*, id, space_id=None, validate_spaces=None)[source]¶
Get a short URL.
Technical preview in 9.4. Gets a single Kibana short URL by its identifier.
- Parameters:
- Returns:
ObjectApiResponse containing the short URL (
id,slug,locator,accessCount,accessDate,createDate).- Raises:
NotFoundError – If the short URL does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> url = client.short_urls.get(id="7f2f37bc-...-d64b0e20df6f") >>> print(url.body["locator"]["id"]) LEGACY_SHORT_URL_LOCATOR
- resolve(*, slug, space_id=None, validate_spaces=None)[source]¶
Resolve a short URL.
Technical preview in 9.4. Resolves a Kibana short URL by its slug and returns the full short URL object, including the locator that can be used to navigate to the target Kibana page.
- Parameters:
- Returns:
ObjectApiResponse containing the short URL (
id,slug,locator,accessCount,accessDate,createDate).- Raises:
NotFoundError – If no short URL exists for the slug.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> resolved = client.short_urls.resolve(slug="my-dashboards") >>> print(resolved.body["id"]) 7f2f37bc-...-d64b0e20df6f
- delete(*, id, space_id=None, validate_spaces=None)[source]¶
Delete a short URL.
Technical preview in 9.4. Deletes a Kibana short URL by its identifier. After deletion, the slug no longer resolves.
- Parameters:
- Returns:
ObjectApiResponse with an empty (
null) body on success.- Raises:
NotFoundError – If the short URL does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> client.short_urls.delete(id="7f2f37bc-...-d64b0e20df6f")
AsyncShortUrlsClient¶
Asynchronous version of the ShortUrlsClient for use with async/await syntax.
- class kibana._async.client.short_urls.AsyncShortUrlsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
AsyncNamespaceClientAsync client for the Kibana Short URLs API.
Kibana URLs may be long and cumbersome; short URLs are much easier to remember and share. Short URLs are created by specifying a locator ID and locator parameters. When a short URL is resolved, the locator ID and locator parameters are used to redirect the user to the right Kibana page.
All Short URL APIs are marked as Technical Preview in Kibana 9.4 and may change in future releases.
Short URLs are space-scoped saved objects: a short URL created in one space is not visible from another space. Every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import AsyncKibana >>> client = AsyncKibana("http://localhost:5601", api_key="...") >>> >>> # Create a short URL using the legacy short URL locator >>> created = await client.short_urls.create( ... locator_id="LEGACY_SHORT_URL_LOCATOR", ... params={"url": "/app/dashboards"}, ... ) >>> slug = created.body["slug"] >>> >>> # Resolve it by slug, then delete it >>> resolved = await client.short_urls.resolve(slug=slug) >>> await client.short_urls.delete(id=resolved.body["id"])
Usage
The AsyncShortUrlsClient provides the same methods as ShortUrlsClient but all methods are async and must be awaited:
from kibana import AsyncKibana import asyncio async def main(): async with AsyncKibana("http://localhost:5601") as client: # Create a short URL (async) created = await client.short_urls.create( locator_id="LEGACY_SHORT_URL_LOCATOR", params={"url": "/app/dashboards"}, ) # Resolve it by slug, then delete it (async) resolved = await client.short_urls.resolve( slug=created.body["slug"] ) await client.short_urls.delete(id=resolved.body["id"]) asyncio.run(main())
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the AsyncShortUrlsClient.
- Parameters:
client (AsyncKibana) – The parent AsyncKibana client instance to delegate requests to.
default_space_id (str | None) – Optional default space ID for all operations.
validate_spaces (bool) – Whether to validate space existence before space-scoped operations (default: True).
Example
>>> short_urls_client = AsyncShortUrlsClient(kibana_client)
- async create(*, locator_id, params, slug=None, human_readable_slug=None, space_id=None, validate_spaces=None)[source]¶
Create a short URL.
Technical preview in 9.4. Creates a Kibana short URL from a locator ID and its parameters. When the short URL is resolved, the locator redirects the user to the right Kibana page.
Warning: locator
paramsare not validated by Kibana, which allows you to pass arbitrary and ill-formed data into the API that can break Kibana. Make sure any data that you send to the API is properly formed.- Parameters:
locator_id (str) – The identifier for the locator (for example,
"LEGACY_SHORT_URL_LOCATOR"or"DASHBOARD_APP_LOCATOR").params (dict[str, Any]) – An object which contains all necessary parameters for the given locator to resolve to a Kibana location.
slug (str | None) – A custom short URL slug. The slug is the part of the short URL that identifies it. It may consist of latin alphabet letters, numbers, and
-._characters and must be between 3 and 255 characters long.human_readable_slug (bool | None) – When
slugis omitted and this is set to True, the API generates a random human-readable slug instead of a random short string.space_id (str | None) – Optional space ID to create the short URL in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
id: The identifier for the short URL
slug: The slug that resolves to this short URL
locator: The locator
id,versionandstateaccessCount / accessDate / createDate: usage metadata
- Return type:
ObjectApiResponse containing the created short URL
- Raises:
BadRequestError – If the request body is invalid (e.g. bad slug).
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> created = await client.short_urls.create( ... locator_id="LEGACY_SHORT_URL_LOCATOR", ... params={"url": "/app/dashboards"}, ... slug="my-dashboards", ... ) >>> print(created.body["slug"]) my-dashboards
- async get(*, id, space_id=None, validate_spaces=None)[source]¶
Get a short URL.
Technical preview in 9.4. Gets a single Kibana short URL by its identifier.
- Parameters:
- Returns:
ObjectApiResponse containing the short URL (
id,slug,locator,accessCount,accessDate,createDate).- Raises:
NotFoundError – If the short URL does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> url = await client.short_urls.get(id="7f2f37bc-...-d64b0e20df6f") >>> print(url.body["locator"]["id"]) LEGACY_SHORT_URL_LOCATOR
- async resolve(*, slug, space_id=None, validate_spaces=None)[source]¶
Resolve a short URL.
Technical preview in 9.4. Resolves a Kibana short URL by its slug and returns the full short URL object, including the locator that can be used to navigate to the target Kibana page.
- Parameters:
- Returns:
ObjectApiResponse containing the short URL (
id,slug,locator,accessCount,accessDate,createDate).- Raises:
NotFoundError – If no short URL exists for the slug.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> resolved = await client.short_urls.resolve(slug="my-dashboards") >>> print(resolved.body["id"]) 7f2f37bc-...-d64b0e20df6f
- async delete(*, id, space_id=None, validate_spaces=None)[source]¶
Delete a short URL.
Technical preview in 9.4. Deletes a Kibana short URL by its identifier. After deletion, the slug no longer resolves.
- Parameters:
- Returns:
ObjectApiResponse with an empty (
null) body on success.- Raises:
NotFoundError – If the short URL does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> await client.short_urls.delete(id="7f2f37bc-...-d64b0e20df6f")