I need to make an API call from within a web services before oper rule using WebServicesClient. I currently have the URL, client_id & secret hard coded in the rule and then passed to the method below.
Is there a way to get the tenant url and PAT (client_id, secret from ISC) from within the rule?
String authenticate(String url, String clientId, String clientSecret) throws Exception {
WebServicesClient client = new WebServicesClient();
Map args = new HashMap();
Map header = new HashMap();
Map payload = new HashMap();
List allowedStatuses = new ArrayList();
String request = String.format("%s/oauth/token?grant_type=client_credentials&client_id=%s&client_secret=%s", url, clientId, clientSecret);
args.put(WebServicesClient.ARG_URL, request);
header.put("Accept", "application/json");
allowedStatuses.add("200");
client.configure(args);
try {
String response = client.executePost(request, payload, header, allowedStatuses);```
Thanks!
@jrossicare
I ended up patching the source with the client_id/secret as (using *_CA) and then updated the “encrypted” attribute with the 2 values.
I then used application.getStringAttributeValue("pat_client_id_CA")) in the WSBOR. I think this is a better solution because the headers don’t have to be entered into each http op. It can just be grabbed from w/in the rule.
One issue that I encountered is that the source patch oper wipes out the existing value even with the “add” op!!
I had to copy/paste the existing value and append “, client_id_CA” to it.
Hi @mario_rod
To add a new variable in the encrypted, you should copy whatever existing values you had in encrypted field and put in the value along with the new variable.
This should resolve the issue.
Whenever you are trying to patch the application for adding your custom values, use your custom variable name. So, that it will not override any existing values. If the custom value should be encrypted then, take a backup of “encrypted” attribute values from the source, then use the replace “op” to update the value.