1
0
-1

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. 

API Properties


Any thoughts or ideas to make the API calls happen in the BeanShell tools?


Appreciate the helps. Thank you!

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      possible CSRF attack could mean you may have not enabled API whitelisting. Add "*" in the general settings under API Domain whitelist. Additionally you can check whether you have generated a API key and using the right one. 

        CommentAdd your comment...
      1.  
        1
        0
        -1

        After lots of trial and error and at the same time researching about the appropriate ways on how to execute aborting a process via BeanShell tools, I ran into this similar question, as below, and finally was able to proceed aborting a process with just 2 simple lines of codes used in Process Monitoring Utility app, instead of using the the API implementation. Wish I found about this sooner though..

        abort processes using SQL/Beanshell

        WorkflowManager wm = (WorkflowManager)AppUtil.getApplicationContext().getBean("workflowManager");
        wm.processAbort(id);


        Not sure why the API implementation is not working in the BeanShell tools, perhaps it is due to some security issues related to Process execution. Might need to check if other normal API calls (for instance get data from lists, etc) works or not. 


        Nevertheless, hope this bring help to whomever needs it!

          CommentAdd your comment...