Skip to content

XurrentApiHelper

Fabian Steiner edited this page Nov 4, 2026 · 2 revisions

XurrentApiHelper

from xurrent import XurrentApiHelper · module xurrent.core

Connection to the Xurrent API: authentication (API token or OAuth client credentials), pagination, retries on rate limits, and helpers for search, archive, trash, audit lines and bulk export/import.

Back to the overview

Constructor

XurrentApiHelper(base_url, api_key=None, api_account=None, resolve_user=True, logger: Logger = None, client_id: Optional[str] = None, client_secret: Optional[str] = None, timeout: Optional[float] = None)

Initialize the Xurrent API helper.

  • base_url: Base URL of the Xurrent API
  • api_key: API key to authenticate with
  • api_account: Account name to use
  • client_id: OAuth client ID to use when fetching an access token
  • client_secret: OAuth client secret to use when fetching an access token
  • resolve_user: Resolve the API user and their teams (default: True)
  • logger: Logger to use (optional), otherwise a new logger is created
  • timeout: Seconds to wait for each HTTP request (default: None, wait without limit)

Methods

create_logger

x_api_helper.create_logger(verbose) -> Logger

Create a logger for the API helper.

  • verbose: Enable verbose logging (debug level)
  • Returns: Logger instance

set_log_level

x_api_helper.set_log_level(level)

Set the log level for the logger and all handlers.

  • level: Log level to set (can be a string, int, or LogLevel enum)

api_call

x_api_helper.api_call(uri: str, method='GET', data=None, per_page=100, raw=False, max_results: Optional[int] = None)

Make a call to the Xurrent API with support for rate limiting and pagination. Automatically handles 401 responses by refreshing the OAuth token if client_id and client_secret are provided.

  • uri: URI to call
  • method: HTTP method to use (default: GET)
  • data: Data to send with the request (optional)
  • per_page: Number of records per page for GET requests, setting to 0/None disables pagination (default: 100)
  • raw: Do not process the request result, e.g. in the case of non-JSON data (default: False)
  • max_results: Stop paginating once this many records were fetched and return at most this many (default: None, fetch all pages)
  • Returns: JSON response from the API or aggregated data for paginated GET

bulk_export

x_api_helper.bulk_export(type: str, export_format='csv', save_as=None, poll_timeout=5)

Make a call to the Xurrent API to perform a bulk export

  • type: Resource type(s) to download, comma-delimited
  • export_format: either 'csv' or 'xlsx' (Default: csv)
  • save_as: Save the results to a file instead of returning the raw result
  • poll_timeout: Seconds to wait between export result polls (Default: 5 seconds)
  • Returns: CSV or XSLX data from the export, ZIP if multiple types supplied

API: POST /export

search

x_api_helper.search(query: str, types: list = None, max_results: Optional[int] = None) -> list

Perform a cross-resource full-text search.

  • query: Search query string (at least two characters; the API answers shorter queries with HTTP 400)
  • types: Optional list of resource types to search (e.g. ['request', 'knowledge-article'])
  • max_results: Return at most this many results, sorted by relevance (default: None, all results)
  • Returns: List of search results

API: GET /search

bulk_import

x_api_helper.bulk_import(data: str, import_type: str, import_format: str = 'csv') -> dict

Perform a bulk import of records.

  • data: CSV/TSV data as a string
  • import_type: Resource type to import (e.g. 'people', 'configuration_items')
  • import_format: Format of the import data ('csv' or 'tsv', default: 'csv')
  • Returns: Import result from the API

API: POST /import

list_archive

x_api_helper.list_archive(queryfilter: dict = None) -> list

List all archived items.

  • queryfilter: Optional query filter parameters
  • Returns: List of archived items

API: GET /archive

list_trash

x_api_helper.list_trash(queryfilter: dict = None) -> list

List all trashed items.

  • queryfilter: Optional query filter parameters
  • Returns: List of trashed items

API: GET /trash

list_audit_lines

x_api_helper.list_audit_lines(queryfilter: dict = None) -> list

List audit log entries.

  • queryfilter: Optional query filter parameters
  • Returns: List of audit log entries

API: GET /audit_lines

custom_fields_to_object

x_api_helper.custom_fields_to_object(custom_fields)

Convert a list of custom fields to a dictionary.

  • custom_fields: List of custom fields
  • Returns: Dictionary containing the custom fields
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.custom_fields_to_object([{'id': 'priority', 'value': 'high'}, {'id': 'status', 'value': 'open'}])
{'priority': 'high', 'status': 'open'}

object_to_custom_fields

x_api_helper.object_to_custom_fields(obj)

Convert a dictionary to a list of custom fields.

  • obj: Dictionary to convert
  • Returns: List of custom fields
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.object_to_custom_fields({'priority': 'high', 'status': 'open'})
[{'id': 'priority', 'value': 'high'}, {'id': 'status', 'value': 'open'}]

create_filter_string

x_api_helper.create_filter_string(filter: dict)

Create a filter string from a dictionary.

  • filter: Dictionary containing the filter parameters
  • Returns: String containing the filter parameters
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.create_filter_string({'status': 'open', 'priority': 'high'})
'status=open&priority=high'
>>> helper.create_filter_string({'status': 'open'})
'status=open'

decode_api_id

x_api_helper.decode_api_id(id: str)

API resource IDs are base64-encoded strings with the padding bytes stripped off. Ensure appropriate padding and decode.

  • id: Encoded Xurrent resource ID
  • Returns: String containing the decoded ID
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.decode_api_id('SGVsbG8sIHdvcmxkIQ')
'Hello, world!'

encode_api_id

x_api_helper.encode_api_id(id: str)

API resource IDs are base64-encoded strings with the padding bytes stripped off. Encode and strip padding.

  • id: Xurrent resource ID to encode
  • Returns: String containing the encoded ID
>>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False)
>>> helper.encode_api_id('Hello, world!')
'SGVsbG8sIHdvcmxkIQ'

Clone this wiki locally