How to make API call in BeanShell tools in a Process?
Confluence User - 14 Sep, 2024
Hi all.
I need to make an API call that is created from Joget's API Builder of a Process element, specifically to abort a process instance. However, while trying to make the API call via BeanShell tools in a Process in the Process Builder, I encountered an issue related to authentication error and was stuck trying to resolve this issue. I print out the error message in the server log, as displayed below.
The snippet of the logic I used to make the API call is as below:
try {
-
HttpPost request = new HttpPost(processAbortUrl);
// Add headers to the request
request.addHeader("api_id", apiId);
request.addHeader("api_key", apiKey);
// Execute the request
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
// Convert the response entity to a string
String responseBody = EntityUtils.toString(entity);
// Parse the JSON response
try {
JSONObject jsonObject = new JSONObject(responseBody);
// Access the 'code' key
String code = jsonObject.getString("code");
I would usually make the API calls from the pages/interfaces side via JavaScript, by referring to below documentation and everything works fine.
Any thoughts or ideas to make the API calls happen in the BeanShell tools?
Appreciate the helps. Thank you!
api;authentication;beanshell
