Skip to content

Relatics Client API Reference

Overview of the RelaticsClient class and associated custom exceptions for interacting with the Relatics DataExchange API.

Client

relatics_toolkit.RelaticsClient(client_id, client_secret, environment)

Client for making OAuth2 get requests to relatics.

Client for making requests to relatics webservices. Will automatically request a token and subsequently do a get request to a webservice.

Parameters:

Name Type Description Default
client_id str

the OAUTH client id obtained from the Relatics environment studio.

required
client_secret str

the OAUTH client secret obtained from the Relatics environment studio.

required
environment str

The subdomain of relaticonline. in https://example.relaticsonline.com, example is the environment string.

required

Returns:

Name Type Description
RelaticsClient RelaticsClient

Class capable of doing get requests to webservices in the specified environment.

Source code in src/relatics_toolkit/ingestion/relatics_client.py
31
32
33
34
def __init__(self, client_id: str, client_secret: str, environment: str) -> None:
    self.client_id = client_id
    self.client_secret = client_secret
    self.environment = environment

get_request(workspace_id, operation, parameters={})

Executes a GET request to the Relatics DataExchange API.

Parameters:

Name Type Description Default
workspace_id str

Workspace identifier

required
operation str

API operation name

required
parameters Dict[str, str]

Query parameters

{}

Returns:

Name Type Description
result Element

Parsed XML root element

Source code in src/relatics_toolkit/ingestion/relatics_client.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def get_request(self, workspace_id: str, operation: str, parameters: Dict[str, str] = {}) -> ET.Element:
    """
    Executes a GET request to the Relatics DataExchange API.

    Args:
        workspace_id: Workspace identifier
        operation: API operation name
        parameters: Query parameters

    Returns:
        result: Parsed XML root element
    """
    api_endpoint = f"https://{self.environment}.relaticsonline.com/DataExchange/{workspace_id}/{operation}"

    access_token, token_type = self._get_token()

    headers = {
        "Authorization": f"{token_type} {access_token}",
        "Content-Type": "application/json",
    }

    body = {
        "Parameters": parameters
    }

    try:
        api_response = requests.get(api_endpoint, headers=headers, json=body)
    except requests.RequestException as e:
        raise APIRequestError(f"API Request failed: {str(e)}") from e

    if api_response.status_code != 200:
        raise APIRequestError(f"API request failed with status code {api_response.status_code}: {api_response.text}")

    try:
        return ET.fromstring(api_response.content)
    except ET.ParseError as e:
        raise XMLParseError("Invalid XML in API response") from e

Exceptions

relatics_toolkit.ingestion.relatics_client.TokenRequestError

Bases: Exception

Raised when token retrieval fails.

Source code in src/relatics_toolkit/ingestion/relatics_client.py
8
9
class TokenRequestError(Exception):
    """Raised when token retrieval fails."""

relatics_toolkit.ingestion.relatics_client.APIRequestError

Bases: Exception

Raised when the API call fails.

Source code in src/relatics_toolkit/ingestion/relatics_client.py
11
12
class APIRequestError(Exception):
    """Raised when the API call fails."""

relatics_toolkit.ingestion.relatics_client.XMLParseError

Bases: Exception

Raised when XML parsing fails.

Source code in src/relatics_toolkit/ingestion/relatics_client.py
14
15
class XMLParseError(Exception):
    """Raised when XML parsing fails."""