PDF_Generation_and_Automation/force-app/main/default/classes/SimplePdfController.cls
2025-08-24 12:01:08 +05:30

52 lines
2.1 KiB
OpenEdge ABL

public with sharing class SimplePdfController {
@AuraEnabled
public static Map<String, Object> callPythonApi(String endpoint, String dataJson) {
try {
System.debug('=== SIMPLE PYTHON API CALL ===');
System.debug('Endpoint: ' + endpoint);
System.debug('Data: ' + dataJson);
// Make HTTP callout
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://160.187.166.67:8000' + endpoint);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
request.setBody(dataJson);
request.setTimeout(120000); // 2 minutes
HttpResponse response = http.send(request);
System.debug('Response Status: ' + response.getStatusCode());
System.debug('Response Body: ' + response.getBody());
Map<String, Object> result = new Map<String, Object>();
if (response.getStatusCode() == 200) {
try {
Map<String, Object> responseData = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
result.put('success', true);
result.put('data', responseData);
} catch (Exception e) {
result.put('success', true);
result.put('data', response.getBody());
}
} else {
result.put('success', false);
result.put('error', 'HTTP ' + response.getStatusCode() + ': ' + response.getBody());
}
return result;
} catch (Exception e) {
System.debug('Error in SimplePdfController: ' + e.getMessage());
System.debug('Stack trace: ' + e.getStackTraceString());
Map<String, Object> errorResult = new Map<String, Object>();
errorResult.put('success', false);
errorResult.put('error', 'Exception: ' + e.getMessage());
return errorResult;
}
}
}