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

"Unrecognized token '$'" error in Add Access JSON of REST Connector

aksharkay
New Contributor III
New Contributor III

Hi,

I have created a REST connection. The target application does not have a separate Add Access and Remove Access API. It only have an Update Access API, so whichever entitlements I mention in the Update Access API request body, they will overwrite the existing accesses of the API.

Therefore, in the Add Access JSON, I am first calling the API to fetch the existing user accesses. In the second API, I am parsing through the response of the first call to store the user's existing accesses and then append the new access to the array. Then I pass this array in the Update Access API request body.

But when I execute an Add Access task, I am getting the following error:

aksharkay_0-1706761734232.png

Below is a response of the user details API from where I am fetching the user's existing accesses: 

tempsnip.png

Below is the Add Access JSON:

{
"call": [
{
"name": "Role",
"successResponses": {
"statusCode": [
200
]
},
"httpParams": "",
"connection": "acctAuth",
"httpContentType": "application/json",
"httpHeaders": {
"Authorization": "${access_token}",
"contentType": "application/json"
},
"httpMethod": "GET",
"url": "https://xxxxxxxx/users/${account.accountID}",
"unsuccessResponses": {
"statusCode": [
400,
401,
404,
500
]
}
},
{
"name": "Role",
"successResponses": {
"statusCode": [
200
]
},
"httpParams": "{\"roles\": ${List responseList = response.Role1.message.data.roles; if(responseList?.size()==0){return [entitlementValue.entitlementID];}else{String roleIds = \"\"; for(Map map:responseList){rolesIds=roleIds+map.id; roleIds=roleIds+\",\";} roleIds=roleIds+entitlementValue.entitlementID; return roleIds.split(\",\");}}}",
"connection": "acctAuth",
"httpContentType": "application/json",
"httpHeaders": {
"Authorization": "${access_token}",
"contentType": "application/json"
},
"httpMethod": "PUT",
"url": "https://xxxxxxxxxx/users/${account.accountID}",
"unsuccessResponses": {
"statusCode": [
400,
401,
404,
500
]
}
}
]
}

 

I noticed that I am getting the error when I add the if-else conditions and loop statements in the httpParams. If I just pass ${[entitlementValue.entitlementID]} then it is working fine. Please let me know what the issue might be.

 

Thanks & Regards,

Akshar

6 REPLIES 6

Dhruv_S
Saviynt Employee
Saviynt Employee

Hi @aksharkay 

Are you able to perform the same operation from postman which you are trying to achieve using REST connector. 

Could you please complete postman request and response.

Please validate the syntax and logic of http params.

Regards,

Dhruv Sharma

aksharkay
New Contributor III
New Contributor III

Hi Dhruv,

Here is a sample request body of the update user roles API:

aksharkay_1-1706864374071.png

The roles attribute takes in an array of role IDs and these values will overwrite the existing roles of the user. It is working as expected from Postman. I am only facing an issue while parsing the response of user's existing roles API.

I validated my httpParams syntax and logic and I was not able to identify any issues with it. I went through other Forum posts which had similar use cases and I updated my JSON accordingly, yet I am getting an error.

Any help on this would be much appreciated!

Thanks & Regards,

Akshar

Hi @aksharkay 

As mentioned by you above, issue is not happening when you are passing ${[entitlementValue.entitlementID]} directly instead of if-else. It seems there is some issue in the else part of the if-else statement of http params.

Could you please check and see if you are getting response in postman for the else part scenario of the if-else block of the http params.

Also could you please try with syntax like below.

https://docs.saviyntcloud.com/bundle/REST-v24x/page/Content/Developers-Handbook.htm#top

 


int size = response.Role1.message.roles?.size();int i = 0;for (Map map : response.Role1.message.roles){if(!map.name.equals(entitlementValue.entitlement_value)){rolesStr=rolesStr+'<role><name>'+map.name+'</name></role>';i++;if(i == size){return rolesStr;}}else{i++;if(i == size){return rolesStr;}}}}</roles></user>",

Regards,

Dhruv Sharma

aksharkay
New Contributor III
New Contributor III

Hi @Dhruv_S ,

That is correct. The use case is working fine from Postman. I need help in identifying what part of the httpParams value is not recognized by Saviynt.

Thanks & Regards,

Akshar

Please refer to the previous post and also share postman request and response with same.

aksharkay
New Contributor III
New Contributor III

This AddAccessJSON worked for me:

{
"call": [
{
"name": "Role",
"successResponses": {
"statusCode": [
200
]
},
"httpParams": "",
"connection": "acctAuth",
"httpContentType": "application/json",
"httpHeaders": {
"Authorization": "${access_token}",
"contentType": "application/json"
},
"httpMethod": "GET",
"url": "xxxxxxxxxxxxxxxxx/users/${account.accountID}",
"unsuccessResponses": {
"statusCode": [
400,
401,
404,
500
]
}
},
{
"name": "Role",
"successResponses": {
"statusCode": [
200
]
},
"httpParams": "{\"roles\": ${List rolesList = response.Role1.message.data.roles.collect{it.id}; rolesList.add(entitlementValue.entitlementID); return rolesList;}}",
"connection": "acctAuth",
"httpContentType": "application/json",
"httpHeaders": {
"Authorization": "${access_token}",
"contentType": "application/json"
},
"httpMethod": "PUT",
"url": "xxxxxxxxxxxxxxx/users/${account.accountID}",
"unsuccessResponses": {
"statusCode": [
400,
401,
404,
500
]
}
}
]
}