Web Service connector - list as BODY attribute

8.3 Patch: p4

I want to send a list of entitlements to external service using Web Service connector.

POST
body:

{
"kid": "$plan.userId$",
"firstName": "$plan.firstName$",
"lastName": "$plan.lastName$",
"roles": [
    "$plan.roles$"
]
}

ProvisioningPlan from logs:

<ProvisioningPlan nativeIdentity="5356431" targetIntegration="xxx" trackingId="07cfeab1659d47b0b2d9cae7aea6d7f4">
  <AccountRequest application="xxx" assignmentIds="b6c8d57caefe4c70aa653ee78ebe3c3e" op="Create">
    <AttributeRequest name="roles" op="Add" value="TestRole"/>
    <AttributeRequest name="firstName" op="Set" value="Max"/>
    <AttributeRequest name="lastName" op="Set" value="Mustermann"/>
    <AttributeRequest name="userId" op="Add" value="A123456"/>
  </AccountRequest>
  <Attributes>
    <Map>
      ...
    </Map>
  </Attributes>
</ProvisioningPlan>

Created json:

{jsonBody={"kid":"A123456","firstName":"Max","lastName":"Mustermann"}, bodyFormat=raw}

How should I prepare BODY template to be able to handle one role and also list of roles?

Hi @krzysiekPienkowski,

you can create an Json Array and put into the json like a Json object

But why are roles not added do json when they are available in plan?

1 Like

Hi @krzysiekPienkowski,

Include the entry below in your application XML and give it a try.

 <entry key="createAccountWithEntReq">
        <value>
          <Boolean>true</Boolean>
        </value>
      </entry>
2 Likes

Unfortunately, did not help.

1 Like

Hi @krzysiekPienkowski,

Add the Before Operation rule into create operation and check the json body.

Reference webServiceBefore Operation Rule

  Map requestMap = requestEndPoint.getBody();
  
  log.error("requestEndPoint body before update = "+requestMap);

  String jsonBody = (String)requestMap.get("jsonBody");  
  
  log.error("jsonbody: "+jsonBody);
1 Like

@ Arun Kumar
I posted json body in my main post. I received it exactly that way.

1 Like

Hi @krzysiekPienkowski ,

If I understand your requirements correctly, it won’t make sense that the createAccountWithEntReq XML entry would not work for you ( credit: @Arun-Kumar ).

What I would like to clarify is the schema that is set up for the connector. Is the “roles” set correctly as Entitlement / ManagedAttribute?

Thanks,

Yes. roles is even set as Managed, Entitlement, Multi-Valued

1 Like

You could try it out in Before Rule for your endpoint to add roles “manually” to the jsonBody as workaround if the connector cannot put the correct information.

>  import org.apache.logging.log4j.LogManager;
>         import org.apache.logging.log4j.Logger;
>  
>         import com.fasterxml.jackson.databind.ObjectMapper;
>         import sailpoint.connector.webservices.EndPoint;
>         import sailpoint.object.ProvisioningPlan;
>  
>  
>         import java.io.IOException;
>         import java.util.Map;
>  
>         Logger log = LogManager.getLogger("Logger.Before");
>  
>         ObjectMapper objectMapper = new ObjectMapper();
>         String jsonString = objectMapper.writeValueAsString(requestEndPoint.getBody());
>  
>         
>         Map modifiedMap = objectMapper.readValue(jsonString, Map.class);
> 
> 
> if (provisioningPlan.getAccountRequests() != null) {
>     for (AccountRequest accountRequest : provisioningPlan.getAccountRequests()) {
>         log.debug("Processing AccountRequest for application: " + accountRequest.getApplication());
> 
>        
>         if (accountRequest.getAttributeRequests() != null) {
>             for (AttributeRequest attributeRequest : accountRequest.getAttributeRequests()) {
>                 String attributeName = attributeRequest.getName();
>                 Object attributeValue = attributeRequest.getValue();
>                 String operation = attributeRequest.getOp().toString();
> 
>                 log.debug("Processing AttributeRequest: name=" + attributeName + ", value=" + attributeValue + ", operation=" + operation);
> 
>                 if ("Add".equals(operation) || "Set".equals(operation)) {
>                     if (attributeName.equals("roles")) {
>                         modifiedMap.computeIfAbsent("roles", k -> new HashMap<String, Object>());
>                         ((Map<String, Object>) modifiedMap.get("roles")).put(attributeValue.toString(), attributeRequest);
>                     } else {
>                         modifiedMap.put(attributeName, attributeValue);
>                     }
>                 }
>             }
>         }
>     }
> }
> 
>         log.debug("Modified map: " + modifiedMap);
>         requestEndPoint.setBody(modifiedMap);
>  
>         log.debug(requestEndPoint.getBody());
2 Likes