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: How to parse a JSON list and use it's values in subsequent call?

yogesh2
Regular Contributor II
Regular Contributor II

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
				]
			}
		}
	]
}

 

4 REPLIES 4

prasannta
Saviynt Employee
Saviynt Employee

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

 

yogesh2
Regular Contributor II
Regular Contributor II

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;}"

 

Hi Prasannta,

What does the last line in the groovy script represent - return companyId ?: null...there is no value being returned between "?" and ":"

Here’s how it works:

  • companyId ?: null means: "If companyId is not null or false (i.e., it has a truthy value), return companyId. If companyId is null or false, return null."

So, in this case, the script is checking if companyId has been assigned a value:

  • If it was found and assigned, the script returns companyId.
  • If companyId is still null or not set, it will return null

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