Click HERE to see how Saviynt Intelligence is transforming the industry. |
07/26/2024 03:54 AM
I have an API that returns below response via a GET call:
[
{
"id": 3714,
"label": "Company",
"required": false,
"visible": true,
"api_visible": true,
"send_to_analytics": false,
"options": [
{
"id": 3350,
"value": "company 1"
},
{
"id": 3351,
"value": "company 2"
},
{
"id": 3352,
"value": "company 3"
},
{
"id": 6442,
"value": "company 4"
}
]
},
{
"id": 3716,
"label": "Location",
"required": false,
"visible": true,
"api_visible": true,
"send_to_analytics": false,
"options": [
{
"id": 6443,
"value": "US"
},
{
"id": 6444,
"value": "IN"
},
{
"id": 6445,
"value": "DE"
}
]
},
{
"id": 3798,
"label": "EmployeeGuid",
"required": false,
"visible": true,
"api_visible": true,
"send_to_analytics": false,
"options": []
},
{
"id": 3800,
"label": "NewHire",
"required": false,
"visible": true,
"api_visible": true,
"send_to_analytics": false,
"options": [
{
"id": 3348,
"value": "Yes"
},
{
"id": 3349,
"value": "No"
}
]
}
]
I have to now check the user's Company Name from this and lets say if user in Saviynt has company 1 then I have to make a put call with the company id i.e. 3350
How to parse the response of the first call (which is a json LIST not an object) and pass the companyid based on that in the next call's parameters?
{
"call": [
{
"name": "GetMapping",
"connection": "acctAuth",
"url": "https://xyz.com/getAttributeMapping",
"httpMethod": "GET",
"httpContentType": "application/json",
"httpHeaders": {
"Authorization": "${access_token}"
},
"successResponses": {
"statusCode": [
200
]
}
},
{
"name": "CreateAccount",
"connection": "acctAuth",
"url": "https://xyz.com/createAccount",
"httpMethod": "PUT",
"httpContentType": "application/json",
"httpParams": "<parameters>",
"httpHeaders": {
"Authorization": "${access_token}"
},
"successResponses": {
"statusCode": [
200
]
}
}
]
}
Solved! Go to Solution.
08/01/2024 10:16 AM
Hi @yogesh2
Can you clarify the data mentioned in the API? What are the different ids? is the response mentioned above for a single user or all attributes stored in endpoint? If you can explain in detail each attribute mentioned in the API response and how you want to use this for account provisioning, that will be helpful to understand your requirement and provide a response.
Thanks
Prasannta Verma
08/01/2024 09:29 PM
Hi @prasannta
Each company name has a corresponding ID which is fixed for all users. We need to send this ID too in the create account call but we don't have this ID stored in Saviynt. (Not sure if we can send it even if we had it stored in Saviynt somehow)
Anyways we have resolved this by following, this code parses the whole JSON I posted earlier to get the company id for the user's company name. Then we send this id in "Company" attribute of the API which expects the company ID:
"Company": "${def companyId; response.call1.message.each { item -> if (item.label == 'Company') { item.options.each { option -> if (option.value == user.companyname) { companyId = option.id.toString(); } } } }; return companyId ?: null;}"
09/06/2024 09:55 AM
Hi Prasannta,
What does the last line in the groovy script represent - return companyId ?: null...there is no value being returned between "?" and ":"
09/06/2024 10:33 AM
Here’s how it works:
So, in this case, the script is checking if companyId has been assigned a value: