Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

REST - Error Unrecognized token '$ AddAccess Json

piyushm
Regular Contributor II
Regular Contributor II

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.

 

{
"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==null)?'POST':'PUT'}",
"httpParams":"${if(response?.Roles1?.message==null) {return'{\"email\": \"'+user?.email+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\",\"roles\": \"[{arsTasks?.entitlement_valueKey.entitlementID}]\"}';} else {return '{\"email\": \"'+account?.accountID+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\",\"Roles\":[{List roleNameList = response?.Roles1?.message?.roles.collect{it.toString()}; roleNameList?.add(entitlementValue.entitlementID.toString());String rolesStr = roleNameList?.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;]}}';}}",
"httpHeaders":{},
"httpContentType": "application/json",
"successResponses": 
{
"statusCode": [200]
},
"unsuccessResponses": 
{
"statusCode": [400, 401]
}
}
 
]
}
 
-----------------------Error--------------------------------
 
Unrecognized token '$': was expecting ('true', 'false' or 'null')\n at [Source: ${if(response?.Roles1?.message==null) {return'{\"email\": \"'+user?.email+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\",\"roles\": \"[{arsTasks?.entitlement_valueKey.entitlementID}]\"}';} else {return '{\"email\": \"'+account?.accountID+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\",\"Roles\":[{List roleNameList = response?.Roles1?.message?.roles.collect{it.toString()}; roleNameList?.add(entitlementValue.entitlementID.toString());String rolesStr = roleNameList?.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;]}}';}}; line: 1, column: 2]","status":"Failed"}}
16 REPLIES 16

SB
Saviynt Employee
Saviynt Employee

it looks like an issue with the if else clause. You can refer the below post for the format to be used

https://forums.saviynt.com/t5/identity-governance/if-else-condition-in-removeaccountjson/m-p/34949#M...


Regards,
Sahil

piyushm
Regular Contributor II
Regular Contributor II

@SB  - I removed all if-else conditions but still I am getting the same error.

Below is the updated json

{
"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": "POST",
"httpParams": "${\"email\": \"'+user?.email+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\"}", 
"httpHeaders": {
        "Authorization": "${access_token}",
        "Accept": "application/json"
      },
"httpContentType": "application/json",
"successResponses": 
{
"statusCode": [200]
},
"unsuccessResponses": 
{
"statusCode": [400, 401]
}
}
 
]
}

 

{"Roles1":{"headers":"hQmfgYEG3KyUPhXWO20/2XsYcRmndnWAv+ek0oWqPbSg4JUgWxzmOibm++sD9TKnVXQTsaZm+tB0w990blzXHywgg6IAeb9c1VHeztmLNOnOgq3wHMLQQULpCZ9It1j3s/NsjLLszA+hGiDnvu2mLoBHgrS0KDwtSv0NKGHK/yDmrS/wt1fNfaReEtq9GfV3pcoO5MfYkFoW4ba2nUvWNVSu5TJpiY0Cc9heqK1MOpSDbpFRDht8Psc6bQuqj1PAvdgaNgmjLo4abprpu9xf2t5h6Jb/aZ1FJrYSejyAtCjLyIdlV0Rk2IvzamOb58N0aCykREu1P5o/Bp9YwFdDehtuaY1THg2YLpYeuvWPQeI5lvrPtmSi4LwS39JisgoQTEivdXLm6hzSIR8eoCbkYcSAelUhutOA1p//1WkAgabcwRKpo1etGtplLpGDP/8v","message":{"responseMessage":"null"},"statusCode":200,"description":null,"status":"Success"},"Roles2":{"message":"Unrecognized token '$': was expecting ('true', 'false' or 'null')\n at [Source: ${\"email\": \"'+user?.email+'\",\"firstName\": \"'+user?.firstname+'\",\"lastName\": \"'+user?.lastname+'\",\"isActive\": \"true\",\"phone\": \"'+user?.phonenumber+'\"}; line: 1, column: 2]","status":"Failed"}}
 

piyushm
Regular Contributor II
Regular Contributor II

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.

{
"call": 
[
{
"name": "Roles",
"connection": "userAuth",
"httpMethod": "GET",
"httpParams": "",
"httpHeaders": {},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [200]
},
"unsuccessResponses": {
"statusCode": [400, 401]
}
},
 
{
"name": "Roles",
"connection": "userAuth",
"httpMethod": "${(response?.Roles1?.message==null)?'POST':'PUT'}"
${if(response?.Roles1?.message==null) {',"httpParams": "{\"email\": \"user?.email\",\"firstName\": \"user?.firstname\",\"lastName\": \"user?.lastname\",\"isActive\": \"true\",\"phone\": \"user?.phonenumber\",\"roles\": [{arsTasks?.entitlement_valueKey.entitlementID}]}"'} else {',"httpParams": "{\"email\": \"account?.accountID\",\"firstName\": \"user?.firstname\",\"lastName\": \"user?.lastname\",\"isActive\": \"true\",\"phone\": \"user?.phonenumber\",\"Roles\":[{List roleNameList = response?.Roles1?.message?.roles.collect{it.toString()}; roleNameList?.add(entitlementValue.entitlementID.toString());String rolesStr = roleNameList?.toString().replace('[','').replace(']','').replace('\"','');return rolesStr;}]}"'}},
"httpHeaders":{},
"httpContentType": "application/json",
"successResponses": 
{
"statusCode": [200]
},
"unsuccessResponses": 
{
"statusCode": [400, 401]
}
}
 
]
}

[This message has been edited by moderator to mask URL hyperlink]

what is Roles1 here ?


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

piyushm
Regular Contributor II
Regular Contributor II

Roles1 is the first call in the json to get the specific user details. 

"httpParams": "\"email\":${user?.email}", 

Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

piyushm
Regular Contributor II
Regular Contributor II

I am not getting what you are suggesting. Can you highlight along with if else condition?

Please try above syntax for all variables 


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

SB
Saviynt Employee
Saviynt Employee

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]}}",

 

https://forums.saviynt.com/t5/identity-governance/if-else-condition-in-removeaccountjson/m-p/34949#M...


Regards,
Sahil

piyushm
Regular Contributor II
Regular Contributor II

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;}]}';}\"}",

piyushm
Regular Contributor II
Regular Contributor II

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

 

{
"email""john.doe@abc.com",
"firstName""Johnd",
"lastName""Dave",
"phone""+123456789",
"isActive"true,
"roles": [2 ]

}

Does hardcoding value from saviynt is working ?


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

piyushm
Regular Contributor II
Regular Contributor II

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. 

instead of dynamic attribute try hardcoding all values and check if API works from Saviynt.


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

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}]}"

piyushm
Regular Contributor II
Regular Contributor II

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
]
}
}
]
}