"""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"], "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'} ) # 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'} ctx.logger.info(f"Proxying DELETE request to Advoware: {endpoint}") result = await advoware.api_call( endpoint, method='DELETE', params=params ) return ApiResponse(status=200, body={'result': result}) except Exception as e: ctx.logger.error(f"Proxy error: {e}") return ApiResponse( status=500, body={'error': 'Internal server error', 'details': str(e)} )