and more in a single search tool across platforms. Read the announcement here. |
11/22/2023 12:32 AM
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
11/22/2023 12:53 AM
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!
11/22/2023 11:34 AM
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')
11/22/2023 06:35 PM
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.
12/01/2023 03:59 AM - last edited on 12/01/2023 04:59 AM by Sunil
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
12/04/2023 08:32 PM
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.
12/09/2023 10:50 AM
Hii Amit,
Sure, let me try it out again.
Thanks,
NM