feat: Enhance Advoware API integration with backward compatibility for data payloads and improve logging for sync events

This commit is contained in:
2026-02-07 15:44:56 +00:00
parent b5abe6cf00
commit 8550107b89
4 changed files with 447 additions and 94 deletions

View File

@@ -130,6 +130,9 @@ class AdvowareAPI:
effective_headers = headers.copy() if headers else {}
effective_headers['Authorization'] = f'Bearer {token}'
effective_headers.setdefault('Content-Type', 'application/json')
# Prefer 'data' parameter over 'json_data' if provided (for backward compatibility)
json_payload = data if data is not None else json_data
async with aiohttp.ClientSession(timeout=effective_timeout) as session:
try:
@@ -137,13 +140,13 @@ class AdvowareAPI:
self.context.logger.debug(f"Making API call: {method} {url}")
else:
logger.debug(f"Making API call: {method} {url}")
async with session.request(method, url, headers=effective_headers, params=params, json=json_data) as response:
async with session.request(method, url, headers=effective_headers, params=params, json=json_payload) as response:
response.raise_for_status()
if response.status == 401:
self._log("401 Unauthorized, refreshing token")
token = self.get_access_token(force_refresh=True)
effective_headers['Authorization'] = f'Bearer {token}'
async with session.request(method, url, headers=effective_headers, params=params, json=json_data) as response:
async with session.request(method, url, headers=effective_headers, params=params, json=json_payload) as response:
response.raise_for_status()
return await response.json() if response.content_type == 'application/json' else None
response.raise_for_status()