Webservice After Rule

Hi,
I am working on webservice connector. I am facing some difficulty duting account aggregation. Th use case is below-
First API call- Give user info such as id, firstname, lastname, email etc.
Second API call- Give user group details based on id.

I need the users only when their email ends with some “@xyz.com” in accounts. I have wriiten a after rule in which I am calling the Second API when email contains @xyz.com. But this code is pulling correct accounts from first page but once it go to to second page , it starts pulling all other records as well where email does not contain @xyz.com. Any thoughts?

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import sailpoint.connector.webservices.Endpoint;
import sailpoint.connector.webservices.WebServicesClient;
import sailpoint.object.Application;
import java.util.ArrayList;

		Map roleMap = new HashMap();
        List finalList = new ArrayList();
        Map map = (Map) requestEndPoint.getHeader();
		String baseurl =(String) application.getAttributeValue("genericWebServiceBaseUrl");
		List allowedStatuses = new ArrayList();
		allowedStatuses.add("2**");
		if (processedResponseObject!= null) 
		{
		for(Map data : processedResponseObject)
		{
			  String email = (String) data.get("login");
			  String id = (String) data.get("id");		
			  if(email != null && email.contains("@xyz.com"))
			  {   
				String url1 = baseurl + "/users/" + id + "/memberships";
				String roleData = null;
				roleData = restClient.executeGet(url1, map, allowedStatuses);
				if (roleData != null) {
					try {
						JSONObject jsonObject = new JSONObject(roleData);
						JSONArray array = (JSONArray) jsonObject.get("entries");
						List roleList = new ArrayList();
						for (int i = 0; i < array.length(); i++) {
							JSONObject obj = (JSONObject) array.get(i);
							String roleName = (String) obj.getJSONObject("group").get("name");
							roleList.add(roleName);
						}
						data.put("Groups", roleList);
					} catch (Exception e) {
						log.info("Error while adding groups");
					}
				}
				roleMap.put(id, data);
			  }
		}		    
		
		for (Map consolidatedMap : roleMap.values()) {
			finalList.add(consolidatedMap);
		}
	}

		Map updatedMapInfo = new HashMap();
        updatedMapInfo.put("data", finalList);
 
        return updatedMapInfo;

Hey @deepakarora,

I would suggest to have multiple Account Aggregation operations. First operation to get the User details like ID, Firstname, Lastname etc. and second operation to get the user groups. This would remove the need for After rule.

Then you can filter the accounts using Account Filtering.

In your case, if you want only ‘@example1.com’ to be aggregated then the filter string will look like email.endsWith("@xyz.com")

For more information on Account Filtering :point_down:

I can do that. I have 100k accounts and out of that only 150 accounts have @xyz.com so If I use filter string then it will take lot of hours to complete the aggregation.

Ohh, that’s too much account to filter. You might have already check this but Is there any way to filter directly in the API call?

Nope. We don’t have such filter in API call.
My question is - what’s the issue with code? It’s working perfectly for firstpage and then why is it not working for next pages?

I don’t see any logical issue in your code. As per my understanding, the after rule will run the no. of pages the API has.

Could you try adding logs under the IF condition where you have the email condition?

Yeah. I will try that.

I added the logs and noticed that rule was pulling all the accounts from the page on which no record exist with email contains @xyz.com. Anyway, I handled the paging through after rule so I can make sure that after rule will run one time only and return the list which have all accounts with @xyz.com. This resolved my issue. Thanks.

1 Like