Making an API call from an after operation rule using beanshell script

Hi I need to make an api call from my after operation rule for one of my webservices connectors.
The problem is I don’t see much in the form of documentation on the subject.
Can I just use a regular HTTP Client from java or is there something more specific to beanshell that can be used?

1 Like

Hi Yaseen,
there are basically two ways of doing it.
You can use the SailPoint Webservices client as described in the after operation rule documentation here: Web Services After Operation Rule | SailPoint Developer Community

You could also use an imported webclient and use it in the after operation rule. Here is some sample code using the apache HttpClient object:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;


try{

		HttpClient client = HttpClient.createDefault();
		HttpGet httpGet = new HttpGet(resourceUrl);

		httpGet.setHeader("Authorization", requestEndPoint.getHeader().get("Authorization"));

		HttpResponse accounts = client.execute(httpGet);
		HttpEntity httpEntAccounts = accounts.getEntity();
		accountResponseString = EntityUtils.toString(httpEntAccounts);

	}catch(Exception ex){
		log.error("Request Failed "+ ex);
	}

Hope this helps.

Hey @Yaseenl !

You can use specific information from the connector, theres alot of documentation about these rules on the compass community

IdentityNow Rule Guide - Web Services After Operation Rule - Compass)

The important thing is to understand the object structure of the response you need to give.
The Return must be a List of Maps, and each map can have its own object( Account)

best

1 Like

In addition to the HttpClient response from @Yaseenl, you could use the WebServiceClient that it’s already available to you on the After/Before WebService Rule

Here are an exemple call using WebServiceClient:

import sailpoint.connector.webservices.EndPoint;
import sailpoint.connector.webservices.WebServicesClient;
import connector.common.JsonUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
        String baseUrl = "https://teste.api/v1/users";
        Map header = new HashMap();
        header.put("Authorization", requestEndPoint.getHeader().get("Authorization"));
        header.put("Content-Type", "application/json");
        List<String> allowStatus = new ArrayList();
        allowStatus.add("2**");
        Map arguments = new HashMap();
        arguments.put(WebServicesClient.ARG_URL, baseUrl);
        restClient.configure(arguments);
        String responseGet = restClient.executeGet(baseUrl,header,allowStatus);
......
1 Like

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