Before Operation Rule Webservice

Hi All,
I am trying to write Before Operation rule, getting this error
```Error in method invocation: Method executeGet(java.lang.String, java.util.HashMap) not found in class\u0027sailpoint.connector.webservices.WebServicesClient\u0027 : at Line: 50 : in file: inline evaluation of: ``import java.util.; import sailpoint.tools.; import connector.common.JsonUtil; . . . \u0027\u0027 : restClient .executeGet ( getUrl , headers ) \n BSF info: SplunkRoleRemove at line: 0 column: columnNo"]

Checked everywhere on executeGet not sure why getting this error, anyone have any idea if I am missing anything? 

```<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="SplunkRoleRemoval" type="WebServiceBeforeOperationRule">
    <Description>Removes a role and updates user roles in Splunk</Description>
    <Source><![CDATA[

import java.util.*;
import sailpoint.tools.*;
import connector.common.JsonUtil;
import sailpoint.object.*;
import connector.common.Util;
import org.json.JSONObject;
import org.json.JSONArray;

log.debug("WSBO Rule Started");

try {
    // STEP 1: Retrieve the userId and role to remove from the provisioning plan
    String userId = null;
    String roleToRemove = null;

    if (provisioningPlan != null) {
        for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
            userId = accReq.getNativeIdentity();
            log.debug("UserId to update: " + userId);
            for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
                String attrName = attReq.getName();
                if ("roles".equalsIgnoreCase(attrName)) {
                    roleToRemove = (String) attReq.getValue();
                }
            }
        }
    }

    if (userId == null || roleToRemove == null) {
        throw new IllegalArgumentException("UserId or role to remove not found in the provisioning plan.");
    }

    log.debug("Role to remove: " + roleToRemove);

    // STEP 2: Get the user's current roles from Splunk via API (GET)
    String bearerToken = "xxxx";  // Use your actual token
    String baseUrl = "xxxxxx";
    String getUrl = baseUrl + userId;  // Full URL to call the API with userId

    // Headers setup
    Map headers = new HashMap();
    headers.put("Authorization", "Bearer " + bearerToken);

    // RestClient setup
    Map args = new HashMap();
    args.put(WebServicesClient.ARG_URL, baseUrl);  // Set the base URL
    restClient.configure(args);  // Configure the restClient with base URL

    // STEP 3: Execute GET request to retrieve current roles using `executeGet` method
    String response = restClient.executeGet(getUrl, headers);  // This is the key change

    // Parse the response JSON to get the roles
    JSONObject jsonResponse = new JSONObject(response);
    JSONArray currentRolesArray = jsonResponse.getJSONArray("roles");

    List updatedRoles = new ArrayList();
    for (int i = 0; i < currentRolesArray.length(); i++) {
        String role = currentRolesArray.getString(i);
        if (!role.equalsIgnoreCase(roleToRemove)) {
            updatedRoles.add(role);
        }
    }

    // STEP 4: Create PATCH body to update the roles in Splunk
    Map updatePayload = new HashMap();
    updatePayload.put("roles", updatedRoles);

    // Convert the payload to JSON
    String jsonPayload = JsonUtil.render(updatePayload);
    log.debug("Final PATCH Payload for Splunk API: " + jsonPayload);

    // STEP 5: Send the PATCH request to Splunk API to update roles
    String patchUrl = baseUrl + userId;
    String patchResponse = restClient.executePatch(patchUrl, jsonPayload, headers);

    log.debug("Splunk API PATCH Response: " + patchResponse);

    // STEP 6: Set the updated payload to the request body
    Map body = requestEndPoint.getBody();  // Access the existing requestEndPoint
    body.put("jsonBody", jsonPayload);
    requestEndPoint.setBody(body);  // Set the updated body

} catch (Exception e) {
    log.debug("Error in WebServiceBeforeOperationRule: " + e.getMessage());
    throw e; // Re-throw the exception to indicate failure in the rule
}

return requestEndPoint;

]]></Source>
</Rule>

Hi @shikhadeliveroo

The way you’re calling executeGet() in your code might be slightly off from what’s expected. You’re missing a parameter.

Use the javadoc in this location to correct your input parameters to this method:

 I went through the code, and it looks like restClient.executeGet isn't a valid method. Instead, we should be using the restClient.invoke() function with the appropriate arguments for GET, PATCH, etc
``` I have not implemented, I want to transparent to you, modified code is as below. add your thought process also.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="SplunkRoleRemoval" type="WebServiceBeforeOperationRule">
    <Description>Removes a role and updates user roles in Splunk</Description>
    <Source><![CDATA[

import java.util.*;
import sailpoint.tools.*;
import connector.common.JsonUtil;
import sailpoint.object.*;
import connector.common.Util;
import org.json.JSONObject;
import org.json.JSONArray;

log.debug("WSBO Rule Started");

try {
    // STEP 1: Retrieve the userId and role to remove from the provisioning plan
    String userId = null;
    String roleToRemove = null;

    if (provisioningPlan != null) {
        for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
            userId = accReq.getNativeIdentity();
            log.debug("UserId to update: " + userId);
            for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
                String attrName = attReq.getName();
                if ("roles".equalsIgnoreCase(attrName)) {
                    roleToRemove = (String) attReq.getValue();
                }
            }
        }
    }

    if (userId == null || roleToRemove == null) {
        throw new IllegalArgumentException("UserId or role to remove not found in the provisioning plan.");
    }

    log.debug("Role to remove: " + roleToRemove);

    // STEP 2: Prepare GET request to retrieve current roles from Splunk
    String bearerToken = "xxxx";  // Use your actual token
    String baseUrl = "https://api.splunk.com/users/";  // Example base URL
    String getUrl = baseUrl + userId;

    Map headers = new HashMap();
    headers.put("Authorization", "Bearer " + bearerToken);
    headers.put("Content-Type", "application/json");

    Map getArgs = new HashMap();
    getArgs.put("method", "GET");
    getArgs.put("url", getUrl);
    getArgs.put("headers", headers);

    String response = (String) restClient.invoke(getArgs);

    // Parse current roles
    JSONObject jsonResponse = new JSONObject(response);
    JSONArray currentRolesArray = jsonResponse.getJSONArray("roles");

    List updatedRoles = new ArrayList();
    for (int i = 0; i < currentRolesArray.length(); i++) {
        String role = currentRolesArray.getString(i);
        if (!role.equalsIgnoreCase(roleToRemove)) {
            updatedRoles.add(role);
        }
    }

    // STEP 3: Prepare PATCH request to update roles in Splunk
    Map updatePayload = new HashMap();
    updatePayload.put("roles", updatedRoles);
    String jsonPayload = JsonUtil.render(updatePayload);
    log.debug("Final PATCH Payload for Splunk API: " + jsonPayload);

    String patchUrl = baseUrl + userId;

    Map patchArgs = new HashMap();
    patchArgs.put("method", "PATCH");
    patchArgs.put("url", patchUrl);
    patchArgs.put("headers", headers);
    patchArgs.put("body", jsonPayload);

    String patchResponse = (String) restClient.invoke(patchArgs);
    log.debug("Splunk API PATCH Response: " + patchResponse);

    // STEP 4: Set updated payload to request body
    Map body = requestEndPoint.getBody();
    body.put("jsonBody", jsonPayload);
    requestEndPoint.setBody(body);

} catch (Exception e) {
    log.debug("Error in WebServiceBeforeOperationRule: " + e.getMessage());
    throw e;
}

return requestEndPoint;

]]></Source>
</Rule>