Apex
Prerequisite — Configure a Named Credential in the calling org that points to the org where DSP is installed.
apex
public with sharing class DspApiClient {
private static final String NAMED_CREDENTIAL_API_NAME = 'TO BE FILLED';
public static String runPipelineBatch(String pipelineApiName, String additionalRetrieveParameters, Boolean chainNextPipeline) {
Map<String, Object> payload = new Map<String, Object>{
'additionalRetrieveParameters' => additionalRetrieveParameters,
'chainNextPipeline' => chainNextPipeline
};
String endpoint = 'callout:' + NAMED_CREDENTIAL_API_NAME + '/services/apexrest/pushtopics/execution/batch/pipeline/' + pipelineApiName;
return doCallAPI(endpoint, payload);
}
public static String runExecutableBatch(String executableApiName, List<Id> sourceRecordIds) {
Map<String, Object> payload = new Map<String, Object>{
'sourceRecordIds' => sourceRecordIds
};
String endpoint = 'callout:' + NAMED_CREDENTIAL_API_NAME + '/services/apexrest/pushtopics/execution/batch/executable/' + executableApiName;
return doCallAPI(endpoint, payload);
}
private static String doCallAPI(String endpoint, Map<String, Object> payload){
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
request.setBody(JSON.serializePretty(payload));
HttpResponse response = new Http().send(request);
if (response.getStatusCode() != 200) {
throw new CustomException('Status Code: ' + response.getStatusCode() + ': ' + response.getBody()); // CustomException - a class that extends Exception.
}
return response.getBody();
}
}