feat: Implement VMH Bankverbindungen sync handlers and API steps for create, update, and delete operations
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import json
|
||||
import datetime
|
||||
|
||||
config = {
|
||||
'type': 'api',
|
||||
'name': 'VMH Webhook Bankverbindungen Create',
|
||||
'description': 'Empfängt Create-Webhooks von EspoCRM für Bankverbindungen',
|
||||
'path': '/vmh/webhook/bankverbindungen/create',
|
||||
'method': 'POST',
|
||||
'flows': ['vmh'],
|
||||
'emits': ['vmh.bankverbindungen.create']
|
||||
}
|
||||
|
||||
async def handler(req, context):
|
||||
try:
|
||||
payload = req.get('body', [])
|
||||
|
||||
context.logger.info("VMH Webhook Bankverbindungen Create empfangen")
|
||||
context.logger.info(f"Payload: {json.dumps(payload, indent=2, ensure_ascii=False)}")
|
||||
|
||||
# Sammle alle IDs aus dem Batch
|
||||
entity_ids = set()
|
||||
|
||||
if isinstance(payload, list):
|
||||
for entity in payload:
|
||||
if isinstance(entity, dict) and 'id' in entity:
|
||||
entity_ids.add(entity['id'])
|
||||
elif isinstance(payload, dict) and 'id' in payload:
|
||||
entity_ids.add(payload['id'])
|
||||
|
||||
context.logger.info(f"{len(entity_ids)} IDs zum Create-Sync gefunden")
|
||||
|
||||
# Emittiere Events
|
||||
for entity_id in entity_ids:
|
||||
await context.emit({
|
||||
'topic': 'vmh.bankverbindungen.create',
|
||||
'data': {
|
||||
'entity_id': entity_id,
|
||||
'action': 'create',
|
||||
'source': 'webhook',
|
||||
'timestamp': req.get('timestamp') or datetime.datetime.now().isoformat()
|
||||
}
|
||||
})
|
||||
|
||||
context.logger.info(f"VMH Create Webhook verarbeitet: {len(entity_ids)} Events emittiert")
|
||||
|
||||
return {
|
||||
'status': 200,
|
||||
'body': {
|
||||
'status': 'received',
|
||||
'action': 'create',
|
||||
'ids_count': len(entity_ids)
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
context.logger.error(f"Fehler beim Verarbeiten des VMH Create Webhooks: {e}")
|
||||
return {
|
||||
'status': 500,
|
||||
'body': {'error': str(e)}
|
||||
}
|
||||
Reference in New Issue
Block a user