We are delighted to share our new EIC Delivery Methodology for efficiently managing Saviynt Implementations and delivering quick time to value. CLICK HERE.

Add access json for Rest(Existing and include new ones)

NM
Regular Contributor II
Regular Contributor II

Hi 

We have a use case where existing group name and group permission are returned as a json array, when a user request for new permission add access json should pass the existing and new one (Requested one)

Postman response

Perm
{
"appGroup": [
{
"GroupName": "dev",
"GPermissions": [
"abc","rty"
]
},
{
"GroupName": "test",
"GPermissions": [
"access","access2"
]
}
]
}

we tried with the below. 

[${List oldresponselist = response.Access1.Perm.appGroup; and then using list add method to add the requested one and return.

But doesn't seem to work, received error {"message":"Unrecognized token '$': was expecting ('true', 'false' or 'null')

Can someone please help out.

 

Thanks

 

6 REPLIES 6

amit_krishnajit
Saviynt Employee
Saviynt Employee

You would need to use multiple API calls in the Add Access JSON. The first call would fetch the existing access for the account and the second would include all the entitlements alongwith the new entitlement to be added. 

Below is a sample of using the entitlements from the first call and calculating the final list of entitlements in the second call.

,\"entitlements\" : ${if(response.'Group1'.message.entitlements?.size()>0){ArrayList finalArr = new ArrayList(); ArrayList arr = response.'Group1'.message.entitlements; arr.eachWithIndex{ val, idx -> Map tempMap = new HashMap(); tempMap.put('value', val.value); tempBuilder = new groovy.json.JsonBuilder(tempMap); finalArr.add(tempBuilder.toString()); }; Map map = new HashMap(); map.put('value',entitlementValue.entitlementID); builder = new groovy.json.JsonBuilder(map); finalArr.add(builder.toString()); return finalArr;}else{ArrayList finalArr = new ArrayList();  Map map = new HashMap(); map.put('value',entitlementValue.entitlementID); builder = new groovy.json.JsonBuilder(map); finalArr.add(builder.toString()); return finalArr;}}

Note - the above code would be part of the httpParams and you may need to modify this as per your requirement of the API. 

Hope this helps! 

 

 

Thanks,
Amit

NM
Regular Contributor II
Regular Contributor II

Hi Amit,

${ArrayList finalArr = new ArrayList(); Map<String,String> map = new HashMap(); map.put(\"GroupName\",\"dev\");map.put(\"Permissions\",[\"${entitlementValue.customproperty1}\"]); builder = new groovy.json.JsonBuilder(map); finalArr.add(builder.toString())

Above code works fine when we hardcode the values in the connection, As soon as we add a binding variable in above case "entitlementValue.customproperty1"(Variable was working fine before adding the above provided code) which is storing permission it gives the same error {"message":"Unrecognized token '$': was expecting ('true', 'false' or 'null')

When you use Groovy there are some basics you would need to understand. As an example, when you have code inside ${}, you won't need to add additional $ to access variables. 

,\"entitlements\" : ${if(response.'Group1'.message.entitlements?.size()>0){ArrayList finalArr = new ArrayList(); ArrayList arr = response.'Group1'.message.entitlements; arr.eachWithIndex{ val, idx -> Map tempMap = new HashMap(); tempMap.put('value', val.value); tempBuilder = new groovy.json.JsonBuilder(tempMap); finalArr.add(tempBuilder.toString()); }; Map map = new HashMap(); map.put('value',entitlementValue.entitlementID); builder = new groovy.json.JsonBuilder(map); finalArr.add(builder.toString()); return finalArr;}else{ArrayList finalArr = new ArrayList();  Map map = new HashMap(); map.put('value',entitlementValue.entitlementID); builder = new groovy.json.JsonBuilder(map); finalArr.add(builder.toString()); return finalArr;}}

In this above example, the Groovy expression starts at the beginning of the evaluation until the end. In order to access the entitlementValue variable, we are not using  ${entitlementValue.entitlementID} again. Since we are already in between evaluation of an expression, the application automatically picks up those variables without the usage of $. 

Hope this makes sense. 

 

 

Thanks,
Amit

NM
Regular Contributor II
Regular Contributor II

Hi @amit_krishnajit ,

I tried with a workaround but when I tried to use entitlement customproperty instead of hardcoding the value it doesn't seem to go in right format (I get an unparseable error from the application API even though it works with harcoding the value

 

Add access json(PUT Call)

"name": "Access",
"connection": "userAuth",
"url": "https://xxx",
"httpMethod": "PUT",
"httpParams": "{\"schemas\":[\"urn:ietf:params:scim:schemas:core:2.0:User\"],\"userName\":\"devtest12.devtest12@co\",\"name\":{\"givenName\":\"DevTest12\",\"familyName\":\"DevTest12\"},\"department\":\"engineering\",\"permissions\":{\"companyPermissions\":[],\"appGroup\":${Map map = new HashMap();ArrayList responseList=response.Access1.message.permissions.appGroup; int size = responseList.size();for (int i=0;i<size;i++){if(responseList.get(i).appGroupName.toString() == \"rx_dev\"){responseList.get(i).appGroupPermissions = [entitlementValue.customproperty22]; return new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(responseList);}}}}}",

Value store in customproperty - "basic_access"

format required on application end 

"appGroupPermissions": [
                    "basic_access"]
 
Could you please help out .. i have tried using replace all and '+with entitlement value but still doesn't work.
 
[This message has been edited by moderator to correct @ mention to an employee username]

 

I would recommend try using eachWithIndex instead of the for-loop and see if that works for you. 

One typical way of troubleshooting these kinds of issues is incorporating one line of code then validating which line of the code works and then modifying it as required. 

 

Thanks,
Amit

NM
Regular Contributor II
Regular Contributor II

Hii Amit, 

Sure, let me try it out again.

 

Thanks,

NM