Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

REST Connector - map response in add access JSON

shivmano
Regular Contributor III
Regular Contributor III

Hi Team - 

For a REST application, I need to send both existing and newly selected entitlements in the addaccessJSON and below is the expected payload. 

shivmano_0-1721736935687.png

I am using the below json to read existing roles and then add the new roles. But it seems to be sending the value as "roles": [MANAGER, SYSADMIN] instead of "roles": ["MANAGER", "SYSADMIN"]

Please can someone advise what changes are needed in the code 

{
"call": [
{
"name": "Role",
"connection": "acctAuth",
"showResponse": true,
"url": "https://*****/api/users?user_ids=${account.accountID}",
"httpMethod": "GET",
"httpHeaders": {
"Accept": "application/json",
"Authorization": "${access_token}"
},
"httpContentType": "application/json"
},
{
"name": "Role",
"connection": "acctAuth",
"showResponse": true,
"url": "https://*****/api/users/update_user",
"httpMethod": "POST",
"httpParams": "{\"filters\": {\"user_id\": \"${account.accountID}\"},\"updates\": {\"allowed_login_methods\": [\"local\"],\"change_password_on_next_login\": true,\"email\": \"${user.email}\",\"password\": \"*****\",\"roles\": [${List rolesList = response.Role1.message.data.users.roles.collect{it.toString()}; rolesList.add(entitlementValue.entitlement_value.toString()); String rolesStr = rolesList.toString().replace('[','').replace(']','');return rolesStr;}],\"username\": \"${user.email.substring(0, user.email.indexOf('@'))}\"}}",
"httpHeaders": {
"Accept": "application/json",
"Authorization": "${access_token}"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
]
},
"unsuccessResponses": {
"statusCode": [
400,
401,
403,
404,
405,
406,
409,
415,
500
]
}
}
]
}

Thank you 

5 REPLIES 5

rushikeshvartak
All-Star
All-Star

{
"call": [
{
"name": "Role",
"connection": "acctAuth",
"showResponse": true,
"url": "https://*****/api/users?user_ids=${account.accountID}",
"httpMethod": "GET",
"httpHeaders": {
"Accept": "application/json",
"Authorization": "${access_token}"
},
"httpContentType": "application/json"
},
{
"name": "Role",
"connection": "acctAuth",
"showResponse": true,
"url": "https://*****/api/users/update_user",
"httpMethod": "POST",
"httpParams": "{\"filters\": {\"user_id\": \"${account.accountID}\"},\"updates\": {\"allowed_login_methods\": [\"local\"],\"change_password_on_next_login\": true,\"email\": \"${user.email}\",\"password\": \"*****\",\"roles\": [${def rolesList = response.Role1.message.data.users.roles.collect{it.toString()}; rolesList.add(entitlementValue.entitlement_value.toString()); return rolesList.collect{ '\"' + it + '\"' }.join(',');}]},\"username\": \"${user.email.substring(0, user.email.indexOf('@'))}\"}}",
"httpHeaders": {
"Accept": "application/json",
"Authorization": "${access_token}"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
]
},
"unsuccessResponses": {
"statusCode": [
400,
401,
403,
404,
405,
406,
409,
415,
500
]
}
}
]
}


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

shivmano
Regular Contributor III
Regular Contributor III

Thank you @rushikeshvartak , it still seems to be throwing an error 

2024-07-23T18:26:33+05:30-ecm-worker--null-c6vlr--2024-07-23T12:56:32.768129934Z stdout F 2024-07-23 12:56:32,767 [quartzScheduler_Worker-8] DEBUG rest.RestProvisioningService - Got Webservice API Response: [headers:[Content-Length: 173, Content-Type: application/json, Date: Tue, 23 Jul 2024 12:56:32 GMT, Strict-Transport-Security: max-age=31536000; includeSubDomains; preload, X-Content-Type-Options: nosniff, X-Frame-Options: sameorigin, X-Xss-Protection: 1; mode=block], responseText:{"error":{"error_code":"ge_invalid_param","fields_errors":{"updates":{"roles":{"message":"One of the roles is incorrect"}}},"message":"Invalid parameters"},"status_code":1}|, cookies:[], statusCode:400]

Enable logs and validate what values are getting sent


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

shivmano
Regular Contributor III
Regular Contributor III

The logs unfortunately are not showing the complete payload. Here is all it shows for the request. Unable to see what is being sent for roles 

2024-07-23T21:43:27+05:30-ecm-worker--null-c6vlr--2024-07-23T16:13:26.630558591Z stdout F 2024-07-23 16:13:26,630 [quartzScheduler_Worker-6] DEBUG rest.RestProvisioningService - Calling Webservice Url - https://*******/api/users/update_user with httpParams - [filters:[user_id:cde0d4b5-daab-4f87-9c87-f8447f8e06c5], updates:[allowed_login_methods:[local], change_password=******password=******

shivmano
Regular Contributor III
Regular Contributor III

@rushikeshvartak I have also tried below code to map the response of roles as list. but this too seems to be not working and the logs does not show what values are being sent. Can you advise please 

${List responseList = response.Role1.message.data.users.roles.collect {it};responseList.add(entitlementValue.entitlement_value);List rolesList = new ArrayList();int count = 0;int size = responseList.size();for (String str : responseList) {count++;rolesList.add('\"' + str + '\"');if (count == size) {return rolesList;}}}