66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Advoware API Proxy - DELETE requests"""
|
|
from typing import Any
|
|
from motia import FlowContext, http, ApiRequest, ApiResponse
|
|
from services.advoware import AdvowareAPI
|
|
|
|
|
|
config = {
|
|
"name": "Advoware Proxy DELETE",
|
|
"description": "Universal proxy for Advoware API (DELETE requests)",
|
|
"flows": ["advoware-proxy"],
|
|
"triggers": [
|
|
http("DELETE", "/advoware/proxy")
|
|
],
|
|
"enqueues": [],
|
|
}
|
|
|
|
|
|
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
|
"""
|
|
Proxy DELETE requests to Advoware API.
|
|
|
|
Query parameters:
|
|
- endpoint: Advoware API endpoint (required)
|
|
- any other params are forwarded to Advoware
|
|
"""
|
|
try:
|
|
# Extract endpoint from query parameters
|
|
endpoint = request.query_params.get('endpoint', '')
|
|
if not endpoint:
|
|
return ApiResponse(
|
|
status=400,
|
|
body={'error': 'Endpoint required as query parameter'}
|
|
)
|
|
|
|
ctx.logger.info("=" * 80)
|
|
ctx.logger.info("🔄 ADVOWARE PROXY: DELETE REQUEST")
|
|
ctx.logger.info("=" * 80)
|
|
ctx.logger.info(f"Endpoint: {endpoint}")
|
|
ctx.logger.info("=" * 80)
|
|
|
|
# Initialize Advoware client
|
|
advoware = AdvowareAPI(ctx)
|
|
|
|
# Forward all query params except 'endpoint'
|
|
params = {k: v for k, v in request.query_params.items() if k != 'endpoint'}
|
|
|
|
result = await advoware.api_call(
|
|
endpoint,
|
|
method='DELETE',
|
|
params=params
|
|
)
|
|
|
|
ctx.logger.info("✅ Proxy DELETE erfolgreich")
|
|
return ApiResponse(status=200, body={'result': result})
|
|
|
|
except Exception as e:
|
|
ctx.logger.error("=" * 80)
|
|
ctx.logger.error("❌ ADVOWARE PROXY DELETE FEHLER")
|
|
ctx.logger.error(f"Endpoint: {request.query_params.get('endpoint', 'N/A')}")
|
|
ctx.logger.error(f"Error: {e}")
|
|
ctx.logger.error("=" * 80)
|
|
return ApiResponse(
|
|
status=500,
|
|
body={'error': 'Internal server error', 'details': str(e)}
|
|
)
|