BPMRESTRequest is the server-side JavaScript helper (System Data toolkit) that calls the BPM REST API from a script with the identity of the running service. Minimal working example for your task lookup:
// script task in a service flow (server side)
var req = new BPMRESTRequest();
req.restServiceName = ""; // leave empty for the local server (or the name of a "Server" of type REST defined in the process app)
req.method = "GET";
req.resource = "/task/" + tw.local.taskId; // relative to /rest/bpm/wle/v1
req.parameters = { "parts": "data" };
var response = tw.system.invokeREST(req);
if (response.httpStatusCode == 200) {
var json = JSON.parse(response.content);
tw.local.taskData = json.data.data.variables; // the task variables
tw.local.subject = json.data.subject;
} else {
throw new Error("REST " + response.httpStatusCode + ": " + response.content);
}For calls that change something (assign, finish, setData) use req.method = "PUT" and pass the query parameters in req.parameters; a JSON body goes into req.body with req.contentType = "application/json". The CSRF token is added by the server for local calls, so nothing extra is needed there; for a remote BPM server define a Server of type "REST" in the process app settings (host, port, user) and put its name in restServiceName.
Two alternatives when BPMRESTRequest is not what you need: the JavaScript API is direct and faster inside the same server (tw.system.findTaskByID(tw.local.taskId) then .subject, .processInstance, .status), and on BAW 20+ the OOB REST external service (import the BAW Swagger) gives you typed business objects.
References