0 votes
2.5k views
in REST API by (140 points)

Hi,

I need your assistance to use BPM REST API in a script task.

I would like to retrieve task details : /rest/bpm/wle/v1/task/<TASKID>?parts=data

I don't know how to define the BPMRESTRequest.

Thanks.

jpcqr

1 Answer

0 votes
by (30.6k points)

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

Related questions

0 votes
1 answer 2.2k views
0 votes
1 answer 764 views
0 votes
1 answer 1.2k views
0 votes
1 answer 2.1k views
0 votes
1 answer 2.2k views
asked May 15, 2016 in REST API by BPM Tips Admin (21.5k points)
0 votes
1 answer 1.0k views
0 votes
1 answer 1.6k views
0 votes
1 answer 2.9k views
0 votes
1 answer 1.9k views
0 votes
1 answer 2.1k views
0 votes
1 answer 997 views
asked May 15, 2016 in REST API by anonymous
0 votes
1 answer 722 views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...