# Before Operation Rule Webservice

**URL:** <https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066>\
**Category:** SHF Discussion and Questions\
**Tags:** identity-security-cloud\
**Created:** [May 19, 2025, 5:38am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066 "2025-05-19T05:38:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shikhadeliveroo](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@shikhadeliveroo](https://developer.sailpoint.com/discuss/u/shikhadeliveroo)\
**Post date:** [May 19, 2025, 5:38am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066/1 "2025-05-19T05:38:06Z")

</div>

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"]

````auto
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>

````

---

<div class="post-metadata">

**Author:** ![sushantkulkarni](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sushantkulkarni/32/35213_2.png) [@sushantkulkarni](https://developer.sailpoint.com/discuss/u/sushantkulkarni)\
**Post date:** [May 19, 2025, 6:12am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066/2 "2025-05-19T06:12:25Z")

</div>

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:

> **[Java Docs | SailPoint Developer Community](https://developer.sailpoint.com/docs/extensibility/rules/java-docs)**
>
> Documentation for rule development in IdentityNow.

---

<div class="post-metadata">

**Author:** ![narayanag](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/narayanag/32/25441_2.png) [@narayanag](https://developer.sailpoint.com/discuss/u/narayanag)\
**Post date:** [May 19, 2025, 7:14am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066/3 "2025-05-19T07:14:06Z")

</div>

> [@shikhadeliveroo](#):
>
> executeGet

````auto
 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>

````

---

<div class="post-metadata">

**Author:** ![shikhadeliveroo](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@shikhadeliveroo](https://developer.sailpoint.com/discuss/u/shikhadeliveroo)\
**Post date:** [May 22, 2025, 7:15am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066/4 "2025-05-22T07:15:42Z")

</div>

Was not using correct syntax. Fixed now.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 21, 2025, 7:16am UTC](https://developer.sailpoint.com/discuss/t/before-operation-rule-webservice/130066/5 "2025-07-21T07:16:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
