0 votes
2.2k views
in Integrations by (120 points)

1 Answer

0 votes
by (30.6k points)

Without a Swagger file the OOB REST external service cannot be generated, so you have three routes:

  1. Write the Swagger yourself - for the two or three operations you need, a 40-line Swagger 2.0 file (question 2739) is often faster than any custom code and gives you typed business objects and a Server definition; import it with External Service > Import from file. Tools like Postman ("Export as OpenAPI") or an example JSON response pasted into a schema generator produce the definitions.
  2. Call it from a script - BPMRESTRequest only addresses BPM's own API; for a foreign REST service use Java's HTTP client from the script (question 2888 has the reusable "REST Call" service) and JSON.parse the answer.
  3. Java integration - a small class with HttpURLConnection / Apache HttpClient in a managed jar; best when authentication is complex (OAuth2 with refresh, mutual TLS, signed requests).
// script task: GET with basic authentication, no Swagger
var url = tw.env.crmUrl + "/customers/" + encodeURIComponent(tw.local.customerId);
var con = new java.net.URL(url).openConnection();
con.setRequestProperty("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString(new java.lang.String(tw.env.crmUser + ":" + tw.env.crmPassword).getBytes("UTF-8")));
con.setRequestProperty("Accept", "application/json"); con.setConnectTimeout(10000); con.setReadTimeout(30000);
var rd = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream(), "UTF-8")), line, text = "";
while ((line = rd.readLine()) != null) text += line;
rd.close();
var json = JSON.parse(text);
tw.local.customer = new tw.object.Customer(); tw.local.customer.name = json.name; tw.local.customer.limit = json.creditLimit;

BPM 8.5.7 note: the external service import expects Swagger 2.0 (OpenAPI 3 came with BAW 20.0.0.2), and TLS endpoints need their signer in the cell truststore (question 2743).

References

Related questions

0 votes
1 answer 2.2k views
0 votes
1 answer 2.5k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.1k views
0 votes
1 answer 2.3k views
asked Jul 11, 2020 in Integrations by Abhishek (120 points)
0 votes
1 answer 1.8k views
0 votes
1 answer 1.1k views
0 votes
2 answers 3.7k views
0 votes
1 answer 2.8k views
asked Jan 4, 2019 in Portal by anonymous

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
...