and more in a single search tool across platforms. Read the announcement here. |
11/02/2023 09:48 PM
Hello,
I am getting the error during the 2nd call in the below Addaccessjson. Please let me know if there is anything wrong here. I am trying if else in the httpparams based on the response from the first call.
Solved! Go to Solution.
11/03/2023 02:09 PM
it looks like an issue with the if else clause. You can refer the below post for the format to be used
11/03/2023 03:30 PM
@SB - I removed all if-else conditions but still I am getting the same error.
Below is the updated json
11/03/2023 04:46 PM - last edited on 11/06/2023 12:00 AM by Sunil
Just to clarify, I want the httpsParams to be replaced based on the if else condition.
I also tried below but it gives syntax exception.
11/03/2023 07:14 PM
what is Roles1 here ?
11/03/2023 11:04 PM
Roles1 is the first call in the json to get the specific user details.
11/05/2023 05:22 PM
"httpParams": "\"email\":${user?.email}",
11/05/2023 06:29 PM
I am not getting what you are suggesting. Can you highlight along with if else condition?
11/05/2023 06:30 PM
Please try above syntax for all variables
11/06/2023 08:00 AM
Below is a sample of httpparams without if else. and with the if else clause, you can refer to the link .
"httpParams": "{\"User\":{\"Active\":true,\"DisplayName\":\"${user.firstname}\",\"Email\":\"${user.email}\",\"FirstName\":\"${user.firstname}\",\"LastName\":\"${user.lastname}\",\"Login\":\"${user.email}\",\"BusinessUnits\":[352]}}",
11/06/2023 04:44 PM
I am using the below format but still getting error,. It is unable to resolve single quotes within replace function.
"Roles2":{"message":"Unexpected character (''' (code 39)): was expecting comma to separate Object entries\n at [Source:
"httpParams":"{\"email\": \"${response.Roles1.message.email}\",\"first_name\": \"${user.firstname}\",\"last_name\": \"${user.lastname}\",\"isActive\": \"true\",\"phone\": \"${user.phonenumber}\",\"Roles\": \"${if(response?.Roles1?.message.equals(null)) {[{arsTasks.entitlement_valueKey.entitlementID}]} else { return '{[${List roleNameList = response.Roles1.message.roles.collect{it.toString()}; roleNameList.add(entitlementValue.entitlement_value.toString());String rolesStr = roleNameList.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;}]}';}\"}",
11/07/2023 04:07 PM
@SB @rushikeshvartak - I am able to resolve the variables but still the roles are not being sent as array because the response i am getting is ""Please provide one or more roles for user...." which is sent only if the role is not provided or not provided in array format.
Below is the httpparams with if else condition for roles attribute (not working).
"httpParams": "{\"email\": \"${account.accountID}\",\"firstName\": \"${user.firstname}\",\"lastName\": \"${user.lastname}\",\"isActive\": \"true\",\"phone\": \"${user.phonenumber}\",\"roles\": \"[${if(response?.Roles1?.message?.roles==null) {entitlementValue.entitlementID} else {List roleNameList = response.Roles1.message.roles.collect{it.toString()}; roleNameList.add(entitlementValue.entitlementID.toString());String rolesStr = roleNameList.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;}}]\"}",
httpparams without if-else condition (working)
"httpParams": "{\"email\": \"${user.email}\",\"firstName\": \"${user.firstname}\",\"lastName\": \"${user.lastname}\",\"isActive\": \"true\",\"phone\": \"${user.phonenumber}\",\"roles\": [${entitlementValue.entitlementID}]}",
In both cases, with or without if-else, the Call logs(below) are same. So I am not sure where else it is failing.
Calling Webservice Url - https://******/v1/am/user with httpParams - [email:r=abc@xyz.com, firstName:xxxx, lastName:xxxx, isActive:true, phone:*****, roles:[2]]
Is it possible the placement of '[]' be causing this issue? Below is the body from postman.
11/07/2023 07:19 PM
Does hardcoding value from saviynt is working ?
11/07/2023 07:32 PM
No. Hardcoding 2(entitlement id) inside if else doesn’t work. Is it a defect that you can’t pass array inside if else?Note there is no key value pair for roles array.
11/07/2023 07:54 PM
instead of dynamic attribute try hardcoding all values and check if API works from Saviynt.
11/17/2023 04:04 AM
You can simplify this "httpParams". For example:
// Construct roles attribute separately
def rolesArray = response?.Roles1?.message?.roles ?: [] // If null, default to an empty array
rolesArray.add(entitlementValue.entitlementID.toString())
def rolesStr = rolesArray.join(',')
// Use the constructed roles attribute in "httpParams"
"httpParams": "{\"email\": \"${account.accountID}\",\"firstName\": \"${user.firstname}\",\"lastName\": \"${user.lastname}\",\"isActive\": \"true\",\"phone\": \"${user.phonenumber}\",\"roles\": [${rolesStr}]}"
11/27/2023 02:46 PM
Below json/format worked for me.
{
"call": [
{
"name": "Roles",
"connection": "userAuth",
"url": "https://****************/v1/am/user?email=${account.accountID}",
"httpMethod": "GET",
"httpParams": "",
"httpHeaders": {},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200
]
},
"unsuccessResponses": {
"statusCode": [
400,
401
]
}
},
{
"name": "Roles",
"connection": "userAuth",
"url": "https://********/*******v1/am/user",
"httpMethod": "${(response?.Roles1?.message?.roles==null)?'POST':'PUT'}",
"httpParams": "{\"email\": \"${account.accountID}\",\"firstName\": \"${user.firstname}\",\"lastName\": \"${user.lastname}\",\"isActive\": \"true\",\"phone\": \"${user?.phonenumber}\",\"roles\": [${if(response?.Roles1?.message?.roles==null) {entitlementValue.entitlementID} else {List roleNameList = response.Roles1.message.roles.collect{it.toString()}; roleNameList.add(entitlementValue.entitlementID.toString());String rolesStr = roleNameList.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;}}]}",
"httpHeaders": {
"Authorization": "${access_token}"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200
]
},
"unsuccessResponses": {
"statusCode": [
400,
401
]
}
}
]
}