Please be sure you’ve read the docs and API specs before asking for help. Also, please be sure you’ve searched the forum for your answer before you create a new topic.
Hello all,
I’m using a web service connector to integrate with an API. The API returns a token in the ‘Cookie’ response header, which I need to pass in subsequent API calls for account aggregation. To achieve this, I’ve created a BeforeConnector rule that:
- Calls the
/token
API to retrieve the token. - Extracts the token from the ‘Cookie’ response header.
- Sets the token as a Bearer token in the actual request header.
Rule:
import java.util.*;
import org.json.*;
import connector.common.JsonUtil;
import sailpoint.connector.webservices.WebServicesClient;
import sailpoint.connector.webservices.EndPoint;
try {
WebServicesClient client = new WebServicesClient();
String url = "Login URI";
Map args = new HashMap();
args.put(WebServicesClient.ARG_URL, url);
client.configure(args);
Map header = new HashMap();
header.put("Content-Type","application/json");
List<String> allowedStatuses = new ArrayList();
allowedStatuses.add("2**");
Map payload = new HashMap();
payload.put("jsonBody", "{\"clientId\":\"ID\",\"secret\":\"PWD\"}");
String response = client.executePost(url, payload, header, allowedStatuses);
// if response contains token it can be updated in the requestEndpoint header or body
// the requestEndpoint will be used for execution of the particular operation configured
log.info("BeforeOperation-Logger:TOKEN-API-RESPONSE-$$$$$$$$");
log.info("BeforeOperation-Logger:response " + response);
//Fetch the USER attribute from the cookies
Map<String, String> cookies = client.getCookies();
String userToken = null;
for (Map.Entry<String, String> entry : cookies.entrySet()) {
if (entry.getKey().startsWith("USER")) {
String[] parts = entry.getValue().split("=");
if (parts.length > 1) {
userToken = parts[1];
break;
}
}
}
log.info("$$$$$$-BeforeOperation-Logger:TOKEN-VALUE-$$$$$$$$");
log.info(" token : " + userToken);
// Information can be fetched from requestEndpoint and updated in the header and body
//Add to the requestEndPoint for usage in the Aggregation Rule
if (userToken != null) {
requestEndPoint.addHeader("X-XSRF-TOKEN", userToken);
}
log.error("BeforeOperation-Logger:requestEndPoint:" + requestEndPoint);
String contextUrl = requestEndPoint.getContextUrl();
log.error("BeforeOperation-Logger:contextUrl:" + contextUrl);
String fullUrl =requestEndPoint.getFullUrl();
log.error("BeforeOperation-Logger:fullUrl:" + fullUrl);
Map body = requestEndPoint.getBody();
log.error("BeforeOperation-Logger:body:" + body);
Map header = requestEndPoint.getHeader();
log.error("BeforeOperation-Logger:header:" + header);
String jsonBody = (String) body.get("jsonBody");
log.error("BeforeOperation-Logger:jsonBody:" + jsonBody);
log.error("BeforeOperation-Logger:END");
return requestEndPoint;
} catch (Exception e) {
log.error("******Token Retreival exception*********")
log.error(e.getMessage(), e);
}
When I call the Accounts aggregation API, I receive a response in the following format:
{
"users": {
"total-results": "243",
"user": [
{
"name": "name",
"email":"email"
},
{
"name": "name-1",
"email":"email-1"
}
]
}
I’ve configured the connector with the following settings:
- Root Path:
$.users.user*
- Response mapping:
name
:$.name
email
:$.email
I’ve also defined a schema with name
and email
fields.
When I enable CCG logs and run the aggregation, it completes successfully with 0 aggregated accounts. However, I don’t see any additional logs beyond the code being printed. Can someone help me identify what I might be missing?"