Making API call with WebServicesClient from within a WSBO rule

Hello,

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!

Hi Mario

I use Headers in the HTTP Operation, then reference those

example:
Header:
X-IDNUrl = https://myTenant.api.identitynow.com
X-IDNClientSecret = $application.private_key_password$

Then in Before Operation rule:

    Map headers = requestEndPoint.getHeader();
    String IDN_URL = (String) headers.get("X-IDNUrl");
    String IDN_CLIENT_ID = (String) headers.get("X-IDNClientId");
    String IDN_CLIENT_SECRET = (String) headers.get("X-IDNClientSecret");

Use PATCH to set IDN PAT

[
    {
        "op": "add",
        "path": "/connectorAttributes/private_key_password",
        "value": "5afc4............................b8bc8"
    }
]

I like to use private_key_password because then it is automatically encrypted.

2 Likes

Thanks @jrossicare
That’s a nice elegant solution. Will give it a shot

@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.

[
  {
    "op": "add",
    "path": "/connectorAttributes/encrypted",
    "value": "client_id_CA"
  }

Isn’t "add’ supposed to add instead of replacing?

1 Like

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.

1 Like

Hi Mario,

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.

[
  {
    "op": "replace",
    "path": "/connectorAttributes/encrypted",
    "value": "client_id_CA"
  }
]

Regards,
Karthi

1 Like

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