brynq-sdk-brynq 2.1.0__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/PKG-INFO +1 -1
  2. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/brynq.py +282 -0
  3. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/credentials.py +155 -0
  4. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/customers.py +85 -0
  5. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/interfaces.py +268 -0
  6. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/mappings.py +102 -0
  7. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/organization_chart.py +242 -0
  8. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/roles.py +263 -0
  9. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/credentials.py +35 -0
  10. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/customers.py +108 -0
  11. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/interfaces.py +181 -0
  12. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/organization_chart.py +70 -0
  13. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/roles.py +95 -0
  14. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/schemas/users.py +132 -0
  15. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/source_systems.py +168 -0
  16. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq/users.py +400 -0
  17. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq.egg-info/PKG-INFO +1 -1
  18. brynq_sdk_brynq-3.0.0/brynq_sdk_brynq.egg-info/SOURCES.txt +23 -0
  19. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/setup.py +1 -1
  20. brynq_sdk_brynq-2.1.0/brynq_sdk_brynq/brynq.py +0 -351
  21. brynq_sdk_brynq-2.1.0/brynq_sdk_brynq.egg-info/SOURCES.txt +0 -9
  22. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq/__init__.py +0 -0
  23. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq.egg-info/dependency_links.txt +0 -0
  24. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq.egg-info/not-zip-safe +0 -0
  25. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq.egg-info/requires.txt +0 -0
  26. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/brynq_sdk_brynq.egg-info/top_level.txt +0 -0
  27. {brynq_sdk_brynq-2.1.0 → brynq_sdk_brynq-3.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_brynq
3
- Version: 2.1.0
3
+ Version: 3.0.0
4
4
  Summary: BrynQ SDK for the BrynQ.com platform
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -0,0 +1,282 @@
1
+ import os
2
+ import requests
3
+ import pandas as pd
4
+ import warnings
5
+ from typing import Union, Literal, Optional, List, Dict, Any
6
+ from .users import Users
7
+ from .organization_chart import OrganizationChart
8
+ from .source_systems import SourceSystems
9
+ from .customers import Customers
10
+ from .interfaces import Interfaces
11
+ from .roles import Roles
12
+ from requests.adapters import HTTPAdapter
13
+ from urllib3.util.retry import Retry
14
+
15
+
16
+ class BrynQ:
17
+ def __init__(self, subdomain: str = None, api_token: str = None, staging: str = 'prod'):
18
+ self.subdomain = os.getenv("BRYNQ_SUBDOMAIN", subdomain)
19
+ self.api_token = os.getenv("BRYNQ_API_TOKEN", api_token)
20
+ self.environment = os.getenv("BRYNQ_ENVIRONMENT", staging)
21
+
22
+ if any([self.subdomain is None, self.api_token is None]):
23
+ raise ValueError("Set the subdomain, api_token either in your .env file or provide the subdomain and api_token parameters")
24
+
25
+ possible_environments = ['dev', 'prod']
26
+ if self.environment not in possible_environments:
27
+ raise ValueError(f"Environment should be in {','.join(possible_environments)}")
28
+
29
+ self.url = 'https://app.brynq-staging.com/api/v2/' if self.environment == 'dev' else 'https://app.brynq.com/api/v2/'
30
+
31
+ # Initialize session with retry strategy
32
+ self.session = requests.Session()
33
+ retry_strategy = Retry(
34
+ total=3, # number of retries
35
+ backoff_factor=0.5, # wait 0.5s * (2 ** (retry - 1)) between retries
36
+ status_forcelist=[500, 502, 503, 504] # HTTP status codes to retry on
37
+ )
38
+ adapter = HTTPAdapter(max_retries=retry_strategy)
39
+ self.session.mount("http://", adapter)
40
+ self.session.mount("https://", adapter)
41
+ self.session.headers.update(self._get_headers())
42
+
43
+ # Initialize components
44
+ self.users = Users(self)
45
+ self.organization_chart = OrganizationChart(self)
46
+ self.source_systems = SourceSystems(self)
47
+ self.customers = Customers(self)
48
+ self.interfaces = Interfaces(self)
49
+ self.roles = Roles(self)
50
+
51
+ def _get_headers(self):
52
+ return {
53
+ 'Authorization': f'Bearer {self.api_token}',
54
+ 'Domain': self.subdomain
55
+ }
56
+
57
+ def get_mapping(self, data_interface_id: int, mapping: str, return_format: Literal['input_as_key', 'columns_names_as_keys', 'nested_input_output'] = 'input_as_key') -> dict:
58
+ """
59
+ DEPRECATED: Use brynq.mappings.get_mapping() instead
60
+ """
61
+ warnings.warn(
62
+ "This method is deprecated. Use brynq.interfaces.mappings.get() instead",
63
+ DeprecationWarning,
64
+ stacklevel=2
65
+ )
66
+ """
67
+ Get the mapping json from the mappings
68
+ :param data_interface_id: The id of the task in BrynQ. this does not have to be the task id of the current task
69
+ :param mapping: The name of the mapping
70
+ :param return_format: Determines how the mapping should be returned. Options are 'input_as_key' (Default, the input column is the key, the output columns are the values), 'columns_names_as_keys', 'nested_input_output'
71
+ :return: The json of the mapping
72
+ """
73
+ # Find the mapping for the given sheet name
74
+ mappings = self.interfaces.mappings._get_mappings(interface_id=data_interface_id)
75
+ mapping_data = next((item for item in mappings if item['name'] == mapping), None)
76
+ if not mapping_data:
77
+ raise ValueError(f"Mapping named '{mapping}' not found")
78
+
79
+ # If the user want to get the column names back as keys, transform the data accordingly and return
80
+ if return_format == 'columns_names_as_keys':
81
+ final_mapping = []
82
+ for row in mapping_data['values']:
83
+ combined_dict = {}
84
+ combined_dict.update(row['input'])
85
+ combined_dict.update(row['output'])
86
+ final_mapping.append(combined_dict)
87
+ elif return_format == 'nested_input_output':
88
+ final_mapping = mapping_data
89
+ else:
90
+ final_mapping = {}
91
+ for value in mapping_data['values']:
92
+ input_values = []
93
+ output_values = []
94
+ for _, val in value['input'].items():
95
+ input_values.append(val)
96
+ for _, val in value['output'].items():
97
+ output_values.append(val)
98
+ # Detect if there are multiple input or output columns and concatenate them
99
+ if len(value['input'].items()) > 1 or len(value['output'].items()) > 1:
100
+ concatenated_input = ','.join(input_values)
101
+ concatenated_output = ','.join(output_values)
102
+ final_mapping[concatenated_input] = concatenated_output
103
+ else: # Default to assuming there's only one key-value pair if not concatenating
104
+ if output_values:
105
+ final_mapping[input_values[0]] = output_values[0]
106
+ return final_mapping
107
+
108
+ def get_mapping_as_dataframe(self, data_interface_id: int, mapping: str, prefix: bool = False) -> pd.DataFrame:
109
+ """
110
+ DEPRECATED: Use brynq.mappings.get_mapping_as_dataframe() instead
111
+ """
112
+ warnings.warn(
113
+ "This method is deprecated. Use brynq.interfaces.mappings.get(as_df = True) instead",
114
+ DeprecationWarning,
115
+ stacklevel=2
116
+ )
117
+ """
118
+ Get the mapping dataframe from the mappings
119
+ :param mapping: The name of the mapping
120
+ :param prefix: A boolean to indicate if the keys should be prefixed with 'input.' and 'output.'
121
+ :return: The dataframe of the mapping
122
+ """
123
+ # Find the mapping for the given sheet name
124
+ mappings = self.interfaces.mappings._get_mappings(interface_id=data_interface_id)
125
+ mapping_data = next((item for item in mappings if item['name'] == mapping), None)
126
+ if not mapping_data:
127
+ raise ValueError(f"Mapping named '{mapping}' not found")
128
+
129
+ # Extract the values which contain the input-output mappings
130
+ values = mapping_data['values']
131
+
132
+ # Create a list to hold all row data
133
+ rows = []
134
+ for value in values:
135
+ # Check if prefix is needed and adjust keys accordingly
136
+ if prefix:
137
+ input_data = {f'input.{key}': val for key, val in value['input'].items()}
138
+ output_data = {f'output.{key}': val for key, val in value['output'].items()}
139
+ else:
140
+ input_data = value['input']
141
+ output_data = value['output']
142
+
143
+ # Combine 'input' and 'output' dictionaries
144
+ row_data = {**input_data, **output_data}
145
+ rows.append(row_data)
146
+
147
+ # Create DataFrame from rows
148
+ df = pd.DataFrame(rows)
149
+
150
+ return df
151
+ def get_system_credential(self, system: str, label: Union[str, list], test_environment: bool = False) -> dict:
152
+ """
153
+ DEPRECATED: Use brynq.credentials.get() instead
154
+ """
155
+ warnings.warn(
156
+ "This method is deprecated. Use brynq.credentials.get() instead",
157
+ DeprecationWarning,
158
+ stacklevel=2
159
+ )
160
+ return self.interfaces.credentials.get_system_credential(system, label, test_environment)
161
+
162
+ def get_interface_credential(self, interface_id: str, system: str, system_type: Optional[str] = None,
163
+ test_environment: bool = False) -> Union[dict, List[dict]]:
164
+ """
165
+ DEPRECATED: Use brynq.credentials.get_interface_credential() instead
166
+ """
167
+ warnings.warn(
168
+ "This method is deprecated. Use brynq.credentials.get() instead",
169
+ DeprecationWarning,
170
+ stacklevel=2
171
+ )
172
+ return self.interfaces.credentials.get(interface_id, system, system_type, test_environment)
173
+
174
+ def get_user_data(self):
175
+ """
176
+ DEPRECATED: Use brynq.users.get_user_data() instead
177
+ """
178
+ warnings.warn(
179
+ "This method is deprecated. Use brynq.users.get_user_data() instead",
180
+ DeprecationWarning,
181
+ stacklevel=2
182
+ )
183
+ return self.users.get()
184
+
185
+ def get_user_authorization_qlik_app(self, dashboard_id):
186
+ """
187
+ DEPRECATED: Use brynq.users.get_user_authorization_qlik_app() instead
188
+ """
189
+ warnings.warn(
190
+ "This method is deprecated. Use brynq.users.get_user_authorization_qlik_app() instead",
191
+ DeprecationWarning,
192
+ stacklevel=2
193
+ )
194
+ return self.users.get_user_authorization_qlik_app(dashboard_id)
195
+
196
+ def get_role_data(self):
197
+ """
198
+ DEPRECATED: Use brynq.users.get_role_data() instead
199
+ """
200
+ warnings.warn(
201
+ "This method is deprecated. Use brynq.users.get_role_data() instead",
202
+ DeprecationWarning,
203
+ stacklevel=2
204
+ )
205
+ return self.roles.get()
206
+
207
+ def create_user(self, user_data: dict) -> requests.Response:
208
+ """
209
+ DEPRECATED: Use brynq.users.create_user() instead
210
+ """
211
+ warnings.warn(
212
+ "This method is deprecated. Use brynq.users.create_user() instead",
213
+ DeprecationWarning,
214
+ stacklevel=2
215
+ )
216
+ return self.users.invite(user_data)
217
+
218
+ def update_user(self, user_id: str, user_data: dict) -> requests.Response:
219
+ """
220
+ DEPRECATED: Use brynq.users.update_user() instead
221
+ """
222
+ warnings.warn(
223
+ "This method is deprecated. Use brynq.users.update_user() instead",
224
+ DeprecationWarning,
225
+ stacklevel=2
226
+ )
227
+ return self.users.update(user_id, user_data)
228
+
229
+ def delete_user(self, user_id: str) -> requests.Response:
230
+ """
231
+ DEPRECATED: Use brynq.users.delete_user() instead
232
+ """
233
+ warnings.warn(
234
+ "This method is deprecated. Use brynq.users.delete_user() instead",
235
+ DeprecationWarning,
236
+ stacklevel=2
237
+ )
238
+ return self.users.delete(user_id)
239
+
240
+ def overwrite_user_roles(self, roles: dict) -> requests.Response:
241
+ """
242
+ DEPRECATED: Use brynq.users.overwrite_user_roles() instead
243
+ """
244
+ warnings.warn(
245
+ "This method is deprecated. Use brynq.users.overwrite_user_roles() instead",
246
+ DeprecationWarning,
247
+ stacklevel=2
248
+ )
249
+ return self.roles.update(roles)
250
+
251
+ def get_source_system_entities(self, system: int) -> requests.Response:
252
+ """
253
+ DEPRECATED: Use brynq.source_systems.get_entities() instead
254
+ """
255
+ warnings.warn(
256
+ "This method is deprecated. Use brynq.source_systems.get_entities() instead",
257
+ DeprecationWarning,
258
+ stacklevel=2
259
+ )
260
+ return self.source_systems.get_entities(system)
261
+
262
+ def get_layers(self) -> List[Dict[str, Any]]:
263
+ """
264
+ DEPRECATED: Use brynq.organization_chart.get_layers() instead
265
+ """
266
+ warnings.warn(
267
+ "This method is deprecated. Use brynq.organization_chart.get_layers() instead",
268
+ DeprecationWarning,
269
+ stacklevel=2
270
+ )
271
+ return self.organization_chart.get_layers()
272
+
273
+ def __enter__(self):
274
+ return self
275
+
276
+ def __exit__(self, exc_type, exc_val, exc_tb):
277
+ self.close()
278
+
279
+ def close(self):
280
+ """Close the session and cleanup resources"""
281
+ if hasattr(self, 'session'):
282
+ self.session.close()
@@ -0,0 +1,155 @@
1
+ import os
2
+ import requests
3
+ from typing import Optional, Union, List, Dict, Any
4
+ import warnings
5
+ from .schemas.credentials import CredentialsConfig
6
+ from brynq_sdk_functions.functions import Functions
7
+
8
+
9
+ class Credentials:
10
+ """
11
+ Handles all credential-related operations for BrynQ SDK.
12
+ """
13
+ def __init__(self, brynq_instance):
14
+ """
15
+ Initialize Credentials manager.
16
+
17
+ Args:
18
+ brynq_instance: The parent BrynQ instance
19
+ """
20
+ self._brynq = brynq_instance
21
+
22
+ def get_system_credential(self, system: str, label: Union[str, list], test_environment: bool = False) -> dict:
23
+ """
24
+ DEPRECATED: Use brynq.interfaces.credentials.get() instead
25
+ """
26
+ warnings.warn("This function is deprecated and will be removed in a future version.", DeprecationWarning, stacklevel=2)
27
+ response = self._brynq.session.get(
28
+ url=f'{self._brynq.url}apps/{system}',
29
+ )
30
+ response.raise_for_status()
31
+ credentials = response.json()
32
+ # rename parameter for readability
33
+ if isinstance(label, str):
34
+ labels = [label]
35
+ else:
36
+ labels = label
37
+ # filter credentials based on label. All labels specified in label parameter should be present in the credential object
38
+ credentials = [credential for credential in credentials if all(label in credential['labels'] for label in labels)]
39
+ if system == 'profit':
40
+ credentials = [credential for credential in credentials if credential['isTestEnvironment'] is test_environment]
41
+
42
+ if len(credentials) == 0:
43
+ raise ValueError(f'No credentials found for {system}')
44
+ if len(credentials) != 1:
45
+ raise ValueError(f'Multiple credentials found for {system} with the specified labels')
46
+
47
+ return credentials[0]
48
+
49
+ def get(self,interface_id: str,system: str,system_type: Optional[str] = None,test_environment: bool = False) -> Union[dict, List[dict]]:
50
+ """
51
+ This method retrieves authentication credentials from BrynQ for a specific interface and system.
52
+
53
+ :param interface_id: ID of the interface to get credentials for
54
+ :param system: The app name to search for in credentials (e.g., 'bob', 'profit')
55
+ :param system_type: Optional parameter to specify 'source' or 'target'. If not provided,
56
+ searches in both lists
57
+ :param test_environment: boolean indicating if the test environment is used (only for 'profit' system)
58
+ :return: Credential dictionary or list of credential dictionaries for the specified system
59
+ """
60
+
61
+ # Fetch the config using a separate method
62
+ config = self._fetch_config(interface_id)
63
+
64
+ matching_credentials = []
65
+
66
+ # If system_type is provided, only search in that list
67
+ if system_type:
68
+ if system_type not in ['source', 'target']:
69
+ raise ValueError("system_type must be either 'source' or 'target'")
70
+ credentials_list = config.get(f'{system_type}s', [])
71
+ for cred in credentials_list:
72
+ if cred.get('app') == system:
73
+ # Check test environment for 'profit'
74
+ if system == 'profit':
75
+ is_test = cred.get('data', {}).get('isTestEnvironment', False)
76
+ if is_test == test_environment:
77
+ matching_credentials.append({'credential': cred, 'type': system_type})
78
+ else:
79
+ matching_credentials.append({'credential': cred, 'type': system_type})
80
+
81
+ # If no system_type provided, search both lists
82
+ else:
83
+ source_credentials = []
84
+ target_credentials = []
85
+
86
+ # Check sources
87
+ for source in config.get('sources', []):
88
+ if source.get('app') == system:
89
+ if system == 'profit':
90
+ is_test = source.get('data', {}).get('isTestEnvironment', False)
91
+ if is_test == test_environment:
92
+ source_credentials.append({'credential': source, 'type': 'source'})
93
+ else:
94
+ source_credentials.append({'credential': source, 'type': 'source'})
95
+
96
+ # Check targets
97
+ for target in config.get('targets', []):
98
+ if target.get('app') == system:
99
+ if system == 'profit':
100
+ is_test = target.get('data', {}).get('isTestEnvironment', False)
101
+ if is_test == test_environment:
102
+ target_credentials.append({'credential': target, 'type': 'target'})
103
+ else:
104
+ target_credentials.append({'credential': target, 'type': 'target'})
105
+
106
+ # Combine matching credentials based on type
107
+ if source_credentials and target_credentials:
108
+ raise ValueError(
109
+ f'Multiple credentials found for system {system} in both source and target. '
110
+ f'Please specify system_type as "source" or "target"'
111
+ )
112
+ matching_credentials = source_credentials or target_credentials
113
+
114
+ # Handle results
115
+ if len(matching_credentials) == 0:
116
+ if system == 'profit':
117
+ raise ValueError(f'No credentials found for system {system} with test_environment={test_environment}')
118
+ else:
119
+ raise ValueError(f'No credentials found for system {system}')
120
+
121
+ if len(matching_credentials) == 1:
122
+ return matching_credentials[0]['credential']
123
+
124
+ if len(matching_credentials) > 1:
125
+ warning_msg = f'Multiple credentials found for system {system}'
126
+ if system_type:
127
+ warning_msg += f' in {system_type}'
128
+ warnings.warn(warning_msg)
129
+ return [cred['credential'] for cred in matching_credentials]
130
+
131
+ def _fetch_config(self, interface_id: str) -> Dict[str, Any]:
132
+ """
133
+ Fetch configuration from BrynQ for a given interface ID.
134
+
135
+ Args:
136
+ interface_id (str): The ID of the interface to fetch configuration for.
137
+
138
+ Returns:
139
+ Dict[str, Any]: Validated credentials configuration.
140
+
141
+ Raises:
142
+ ValueError: If the response data is invalid.
143
+ requests.exceptions.RequestException: If the API request fails.
144
+ """
145
+ response = self._brynq.session.get(
146
+ url=f'{self._brynq.url}interfaces/{interface_id}/config/auth'
147
+ )
148
+ response.raise_for_status()
149
+
150
+ try:
151
+ config_data = response.json()
152
+ valid_data, _ = Functions.validate_pydantic_data(config_data, CredentialsConfig, debug=False)
153
+ return valid_data[0]
154
+ except ValueError as e:
155
+ raise ValueError(f"Invalid credentials configuration received from API: {str(e)}")
@@ -0,0 +1,85 @@
1
+ from typing import List, Dict, Any, Optional
2
+ import requests
3
+ from requests import Response
4
+ from .schemas.customers import CustomerSchema, CustomerContractDetailsSchema
5
+ from brynq_sdk_functions.functions import Functions
6
+
7
+ class Customers:
8
+ """Class for interacting with BrynQ customer endpoints"""
9
+
10
+ def __init__(self, brynq):
11
+ """Initialize Customers class
12
+
13
+ Args:
14
+ brynq: Parent BrynQ instance for authentication and configuration
15
+ """
16
+ self.brynq = brynq
17
+
18
+ def get(self) -> List[Dict[str, Any]]:
19
+ """Get all customers this token has access to.
20
+
21
+ Returns:
22
+ List[Dict[str, Any]]: List of customer objects with validated data
23
+
24
+ Raises:
25
+ requests.exceptions.RequestException: If the API request fails
26
+ ValueError: If the response data doesn't match the expected schema
27
+ """
28
+ response = self.brynq.session.get(
29
+ f"{self.brynq.url}customers",
30
+ )
31
+ response.raise_for_status()
32
+
33
+ try:
34
+ customers_data = response.json()
35
+ valid_data, _ = Functions.validate_pydantic_data(customers_data, CustomerSchema, debug=False)
36
+ return valid_data
37
+ except ValueError as e:
38
+ raise ValueError(f"Invalid customer data received from API: {str(e)}")
39
+
40
+ def get_all_contract_details(self) -> List[Dict[str, Any]]:
41
+ """Get all customers contract details.
42
+
43
+ Returns:
44
+ List[Dict[str, Any]]: List of customer contract details with validated data
45
+
46
+ Raises:
47
+ requests.exceptions.RequestException: If the API request fails
48
+ ValueError: If the response data doesn't match the expected schema
49
+ """
50
+ response = self.brynq.session.get(
51
+ f"{self.brynq.url}customers/contract-details",
52
+ )
53
+ response.raise_for_status()
54
+
55
+ try:
56
+ contract_details = response.json()
57
+ valid_data, _ = Functions.validate_pydantic_data(contract_details, CustomerContractDetailsSchema, debug=False)
58
+ return valid_data
59
+ except ValueError as e:
60
+ raise ValueError(f"Invalid contract details received from API: {str(e)}")
61
+
62
+ def get_contract_details_by_id(self, customer_id: int) -> Dict[str, Any]:
63
+ """Get contract details for a specific customer.
64
+
65
+ Args:
66
+ customer_id (int): The ID of the customer to get contract details for.
67
+
68
+ Returns:
69
+ Dict[str, Any]: Contract details for the specified customer.
70
+
71
+ Raises:
72
+ ValueError: If the response data is invalid.
73
+ requests.exceptions.RequestException: If the API request fails.
74
+ """
75
+ response = self.brynq.session.get(
76
+ f"{self.brynq.url}customers/{customer_id}/contract-details",
77
+ )
78
+ response.raise_for_status()
79
+
80
+ try:
81
+ contract_details = response.json()
82
+ valid_data, _ = Functions.validate_pydantic_data(contract_details, CustomerContractDetailsSchema, debug=False)
83
+ return valid_data[0]
84
+ except ValueError as e:
85
+ raise ValueError(f"Invalid contract details received from API: {str(e)}")