Leveraging Intelligent Recommendations for Operational Transformation. AMS Partners click HERE | EMEA/APJ Partners click HERE |
01/31/2024 08:36 PM
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:
Below is a response of the user details API from where I am fetching the user's existing accesses:
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
Solved! Go to Solution.
02/02/2024 12:49 AM
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
02/02/2024 01:06 AM
Hi Dhruv,
Here is a sample request body of the update user roles API:
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
02/04/2024 11:56 PM - edited 02/05/2024 12:01 AM
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
02/05/2024 12:03 AM - edited 02/05/2024 12:04 AM
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
02/05/2024 04:55 AM
Please refer to the previous post and also share postman request and response with same.
02/06/2024 09:14 PM
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
]
}
}
]
}