Need Help with Rest Json

MTewari
New Contributor II
New Contributor II

Hi All,

I want to send a couple of attributes based on condition in Rest.

{
"accountIdPath": "call1.message.id",
"responseColsToPropsMap": {
"displayname": "call1.message.fullname~#~char",
"customproperty1": "call1.message.email~#~char",
"customproperty2": "call1.message.firstname~#~char",
"customproperty3": "call1.message.lastName~#~char",
"name": "call1.message.login~#~char",
"customproperty5": "call1.message.mention-name~#~char",
"customproperty16": "call1.message.sso-identifier~#~char"
},
"call": [
{
"name": "call1",
"connection": "acctAuth",
"url": "https://xxxxxx/api/users/${account.accountID}",
"httpMethod": "PUT",
"httpParams": "{\"login\":\"${user.locationdesc}\",\"sso-identifier\":\"${user.locationdesc}\",\"email\":\"${user.email}\",\"firstname\":\"${user.firstname}\",\"lastname\":\"${user.lastname}\",\"fullname\":\"${user.displayname}\",\"band\":\"${user.employeeclass}\",\"sharp-user-id\":\"${user.username}\",\"phone-work\":\"${user.phonenumber}\",\"roles\":{\"role\":{\"name\":\"ABI Read Only\"}},\"requisition-approval-limit\": {\"name\":\"${user.country}-${user.employeeclass}\"}, \"invoice-approval-limit\":{\"name\":\"${user.country}-${user.employeeclass}\"},\"manager\":\"${if(account.customproperty4.equals(true)){\"login\":\"${userManager.locationdesc}\"}else{''}}\"}",
"httpHeaders": {
"accessToken": "${access_token}",
"Accept": "application/json"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
]
}
}
]
}

Here I want to send :

\"phone-work\":\"${user.phonenumber}\" only if phone number value is there.

ex. if(phonenumber=null){\"phone-work\":\"${user.phonenumber}\"}else(null)

Please can someone help here on priority.

7 REPLIES 7

dgandhi
All-Star
All-Star

Try some below sample:

{\"short_description\":\"${if(task.source=='PROVRULE' && task?.tasktype==14){'[NO ACTION REQUIRED]:'} else if(task.tasktype==14){'[NO ACTION REQUIRED]:'} else if(task.requestKey?.requesttype==3 || task.requestKey?.requesttype==11 && task.tasktype==3){''}else if(task.tasktype==2 && (allEntitlementsValues==null || allEntitlementsValues.isEmpty() || allEntitlementsValues=='')){''}else if(task.source=='PROVRULE' && task?.tasktype==2){''}else if(task.tasktype==2){''}else if(task.requestKey?.requesttype != 3 && task?.tasktype==1){''}else if(task.tasktype==6){''}else if(task.tasktype==12){''}else{task.tasktype}}

https://forums.saviynt.com/t5/saviynt-knowledge-base/how-to-support-if-else-condition-in-connector-j...

https://forums.saviynt.com/t5/identity-governance/syntax-for-if-else-condition-in-rest-connector-fet...

 

Thanks,
Devang Gandhi
If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

MTewari
New Contributor II
New Contributor II

Thanks I'll try this and get back to you

MTewari
New Contributor II
New Contributor II

I am trying this in the above json 

\"${if(user.employeeType.equals('Internal Employee')){\"default-address\":{\"country\":{\"code\":\"${user.country}\"},\"city\":\"${user.city}\",\"street1\":\"${user.street}\",\"postal-code\":\"${user.customproperty31}\",\"state\":\"${user.customproperty58.substring(user.customproperty58.lastIndexOf('||')+2)}\"}else{''}\"

But it is not working.

Complete Json :

{
"accountIdPath": "call1.message.id",
"responseColsToPropsMap": {
"displayname": "call1.message.fullname~#~char",
"customproperty1": "call1.message.email~#~char",
"customproperty2": "call1.message.firstname~#~char",
"customproperty3": "call1.message.lastName~#~char",
"name": "call1.message.login~#~char",
"customproperty5": "call1.message.mention-name~#~char",
"customproperty16": "call1.message.sso-identifier~#~char"
},
"call": [
{
"name": "call1",
"connection": "acctAuth",
"url": "https://xxxxxxx/api/users/${account.accountID}",
"httpMethod": "PUT",
"httpParams": "{\"login\":\"${user.locationdesc}\",\"sso-identifier\":\"${user.locationdesc}\",\"email\":\"${user.email}\",\"firstname\":\"${user.firstname}\",\"lastname\":\"${user.lastname}\",\"fullname\":\"${user.displayname}\",\"band\":\"${user.employeeclass}\",\"sharp-user-id\":\"${user.username}\",\"phone-work\":\"${user.phonenumber}\",\"roles\":{\"role\":{\"name\":\"ABI Read Only\"}},\"${if(user?.employeeType.equals('Internal Employee')){\"default-address\":{\"country\":{\"code\":\"${user.country}\"},\"city\":\"${user.city}\",\"street1\":\"${user.street}\",\"postal-code\":\"${user.customproperty31}\",\"state\":\"${user.customproperty58.substring(user.customproperty58.lastIndexOf('||')+2)}\"}else{''}\",\"requisition-approval-limit\": {\"name\":\"${user.country}-${user.employeeclass}\"}, \"invoice-approval-limit\":{\"name\":\"${user.country}-${user.employeeclass}\"},\"manager\":\"${if(account.customproperty4.equals(true)){\"login\":\"${userManager.locationdesc}\"}else{''}}\"}",
"httpHeaders": {
"accessToken": "${access_token}",
"Accept": "application/json"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
]
}
}
]
}

what is the error that you are getting?

 

Thanks,
Devang Gandhi
If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

MTewari
New Contributor II
New Contributor II

There is no error, but the code is going to else condition. Pending task is getting completed but nothing is getting done.

MTewari
New Contributor II
New Contributor II

Hi  dgandhi,

I am trying this Json.  And getting the below error.

{
"accountIdPath": "call1.message.id",
"responseColsToPropsMap": {
"displayname": "call1.message.fullname~#~char",
"customproperty1": "call1.message.email~#~char",
"customproperty2": "call1.message.firstname~#~char",
"customproperty3": "call1.message.lastName~#~char",
"name": "call1.message.login~#~char",
"customproperty5": "call1.message.mention-name~#~char",
"customproperty16": "call1.message.sso-identifier~#~char"
},
"call": [
{
"name": "call1",
"connection": "acctAuth",
"url": "https://xxxxxxxxxxx/api/users/${account.accountID}",
"httpMethod": "PUT",
"httpParams": "{\"login\":\"${user.locationdesc}\",\"sso-identifier\":\"${user.locationdesc}\",\"email\":\"${user.email}\",\"firstname\":\"${user.firstname}\",\"lastname\":\"${user.lastname}\",\"fullname\":\"${user.displayname}\",\"band\":\"${user.employeeclass}\",\"sharp-user-id\":\"${user.username}\",\"phone-work\":\"${if(user.phonenumber!=null){user.phonenumber}else{''}}\",\"roles\":{\"role\":{\"name\":\"ABI Read Only\"}},\"requisition-approval-limit\":{\"name\":\"${user.country}-${user.employeeclass}\"}, \"invoice-approval-limit\":{\"name\":\"${user.country}-${user.employeeclass}\"},\"default-address\":{\"country\":{\"code\":\"${if(user.employeeType.equals('Internal Employee')){user.country}else{''}}\"},\"city\":\"${if(user.employeeType!='Internal Employee'){''}else{user.city}}\",\"street1\":\"${if(user.employeeType.equals('Internal Employee'){user.street}else{''}}\",\"postal-code\":\"${if(user.employeeType!='Internal Employee'){''}else{user.customproperty31}}\",\"state\":\"${user.customproperty58.substring(user.customproperty58.lastIndexOf('||')+2)}\"}}",
"httpHeaders": {
"accessToken": "${access_token}",
"Accept": "application/json"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
]
}
}
]
}

ERROR:

"auditDetails":{"call1":[{"headers":{"Transfer-Encoding":"chunked","x-request-id":"807e4cbf-eeef-44ec-89df-c26a572bc20a","server":"envoy","vary":"Accept","x-frame-options":"SAMEORIGIN","Connection":"keep-alive","x-permitted-cross-domain-policies":"none","x-download-options":"noopen","Date":"Fri, 18 Aug 2023 06:10:24 GMT","strict-transport-security":"max-age=31536000; includeSubDomains;","set-cookie":"_mkra_ctxt=6a535aec70063c3aeecc970c0fd0d0fa--400; path=/; max-age=5; secure; HttpOnly","x-coupa-request-id":"807e4cbf-eeef-44ec-89df-c26a572bc20a","x-xss-protection":"1; mode=block","x-content-type-options":"nosniff","x-robots-tag":"none","referrer-policy":"strict-origin-when-cross-origin","x-runtime":"0.140374","cache-control":"no-cache","Content-Type":"application/json; charset=utf-8","status":"400 Bad Request"},"message":{"errors":{"user":["Default Address {nil=>[\"Unable to find valid Country record for country with keys {\\\"code\\\"=>\\\"${if(user.employeeType.equals('Internal Employee')){user.country}else{''}}\\\"}. Possible keys are [\\\"id\\\", \\\"code\\\", \\\"name\\\", \\\"updated_name\\\"]. Please verify your xml.\"]}"],"user.default_address":["Unable to find valid Country record for country with keys {\"code\"=>\"${if(user.employeeType.equals('Internal Employee')){user.country}else{''}}\"}. Possible keys are [\"id\", \"code\", \"name\", \"updated_name\"]. Please verify your xml."],"warnings":null}},"statusCode":400,"description":null,"status":"Failed"}]},"

MTewari
New Contributor II
New Contributor II

Can anyone please help me on this ?