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.
Hi All,
I have configured WSC connector with HTTP operations like test connection, aggregation, entitlement, etc. The token got expired after sometime, how to refresh the token and use it in HTTP operation. The response is in xml format. Tried the below code but it working.
Used custom authentication and created custom auth http operation.
try {
String username = (String) application.getAttributeValue(“username”);
String password = (String) application.getAttributeValue(“password”);
WebServicesClient client = new WebServicesClient();
String url = “https://{{lab_server}}:{{port}}/services/auth/login”;
Map args = new HashMap();
args.put(WebServicesClient.ARG_URL, url);
client.configure(args);
// Configure the header
Map header = new HashMap();
header.put(“Content-Type”, “application/xml”);
List allowedStatuses = new ArrayList();
allowedStatuses.add(“2**”);
// Construct the raw XML payload
String payload = “”
+ “” + username + “”
+ “” + password + “”
+ “”;
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("response: " + response);
// Fetch the session token from the response XML
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(response)));
document.getDocumentElement().normalize();
// Assuming the token is in an element named “token”
String apiToken = document.getElementsByTagName(“token”).item(0).getTextContent();
log.info("API token: " + apiToken);
// Add to the requestEndPoint to authenticate to the endpoint
requestEndPoint.addHeader(“Authorization”, apiToken);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
]]>
@uday_kilambi I have already try that by adding return requestEndPoint; in the end line of code. But it was throwing error token timed out when i attached this rule to Account aggregation operation.
Whether iam doing it correctly or not i don’t know iam bit confused. If i have gave the token hardcoded in the body of the request payload with rule attached i am not able to do the aggregation. If i remove the rule and try the aggregation with hardcoded token it was successfull.
Also in Account operation Header i have configured Authorization - apiToken and use this variable in the body for token value as $application.apiToken$ is this correct way of doing it?
Have you tried logging your apiKey that you set in the rule, did you verify if it is returning the right format of apiKey. If you capture the apiKey in the rule, try using it directly on postman or hardcoding it on the header and verify that it is the valid token for your API.
@Santhakumar you can also store the access token in the OOTB attribute called accesstoken and refer in other HTTP operations with $application.accesstoken$
Hi team,
I have resolved this issue by creating webservice AfterOperation Rule for Custom Authentication operation and map the custom schema attribute in the rule.
After that i have used the variable $application.apiToken_CA$ inside body for other operations.
Thanks @uday_kilambi@Abhinov7@udayputta for your inputs