Capture all similar values from API response

{
“result”: {
“parent”: “”,
“made_sla”: “true”,
“watch_list”: “”,
“sn_esign_document”: “”,
“access_requested_for”: {
“link”: “https://service-now.com/api/now/system_user/9b211591db”,
“value”: “123”
},
“upon_reject”: “cancel”,
“system_updated_on”: “2023-07-14 20:18:27”,
“task_effective_number”: “AC677”,
“approval_history”: “”,
“access_requested_for”: {
“link”: “https://service-now.com/api/now/system_user/9b211591”,
“value”: “456”
},
“select_role”: “37bb9”,
“skills”: “”,
“number”: “ACR0033677”,
“system_updated_by”: “vby01”,
“opened_by”: {
“link”: “https://service-now.com/api/now/system_user/aa562d701”,
“value”: “aa562d7014c5144b06a”
},
“user_input”: “”,
“system_created_on”: “2023-07-14 12:22:32”,
“system_domain”: {
“link”: “https://service-now.com/api/now/system_user_group/global”,
“value”: “global”
},
“state”: “2”,
“route_reason”: “”,
“system_created_by”: “test”,
“order”: “”,
“access_requested_for”: {
“link”: "https://service-now.com/api/now/system_user/9b211591d,
“value”: “789”
},
“closed_at”: “”,
“cmdb_ci”: “”,
“access_requested_for”: {
“link”: “https://service-now.com/api/now/system_user/9b211591db”,
“value”: “167”
},
“cmdb_ci_business_app”: “”,
“contract”: “”,

}

}

In the above API response how to get all “value” for access_requested_for i.e. I have to capture 123,456,789 and 167 from the response. Here it’s 4 but it can be n times, i.e. we don’t how many values we will get in response. API response is in JSON format.

@c3f1e68294fdcf4a1f0a817ca

Please use desirialize json activity… and this looks like a json array and also this might not be complete json

How you access is say the json array is having key as key then use deserialized json output in the for loop like below

Json("Key")

And type argument will be jobject

Inside the loop use currentItem("access_requested_for").ToString

If you can provide the full data in a file or so we can properly give the data

Also you can check this

Cheerd

Thanks for the response. Here is the complete response.

{
“result”: {
“parent”: “”,
“made_sla”: “true”,
“watch_list”: “”,
“sn_esign_document”: “”,
“upon_reject”: “cancel”,
“sys_updated_on”: “2023-08-31 15:30:00”,
“task_effective_number”: “ACR012345”,
“approval_history”: “”,
“select_role”: “37bfe0ecc4bcbd8”,
“skills”: “”,
“number”: “ACR012345”,
“sys_updated_by”: “dummy_user”,
“opened_by”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/abcdef123456789”,
“value”: “abcdef123456789”
},
“user_input”: “”,
“sys_created_on”: “2023-08-31 10:00:00”,
“sys_domain”: {
“link”: “https://dummy-link.com/api/now/table/sys_user_group/global”,
“value”: “global”
},
“state”: “2”,
“route_reason”: “”,
“sys_created_by”: “dummy_creator”,
“order”: “”,
“access_requested_for”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/1234567890”,
“value”: “1234567890”
},
“closed_at”: “”,
“cmdb_ci”: “”,
“cmdb_ci_business_app”: “”,
“contract”: “”,
“impact”: “3”,
“active”: “true”,
“work_notes_list”: “”,
“business_service”: “”,
“priority”: “4”,
“sys_domain_path”: “/”,
“time_worked”: “”,
“expected_start”: “”,
“opened_at”: “2023-08-31 09:45:00”,
“business_duration”: “”,
“group_list”: “”,
“work_end”: “”,
“approval_set”: “2023-08-31 15:45:00”,
“work_notes”: “”,
“request_access_to”: {
“link”: “https://dummy-link.com/api/now/table/x_amge2_access_app_access_listing/xyz987”,
“value”: “xyz987”
},
“universal_request”: “”,
“short_description”: “”,
“access_type”: “add”,
“correlation_display”: “”,
“work_start”: “”,
“assignment_group”: {
“link”: “https://dummy-link.com/api/now/table/sys_user_group/789abc”,
“value”: “789abc”
},
“additional_assignee_list”: “”,
“description”: “”,
“calendar_duration”: “”,
“close_notes”: “”,
“service_offering”: “”,
“sys_class_name”: “x_amge2_access_app_access_request”,
“closed_by”: “”,
“follow_up”: “”,
“sys_id”: “dummy_sys_id”,
“contact_type”: “self-service”,
“sn_esign_esignature_configuration”: “”,
“urgency”: “”,
“company”: “”,
“justification”: “Dummy justification text”,
“reassignment_count”: “0”,
“activity_due”: “”,
“assigned_to”: “”,
“comments”: “”,
“approval”: “approved”,
“sla_due”: “”,
“comments_and_work_notes”: “”,
“due_date”: “”,
“sys_mod_count”: “2”,
“sys_tags”: “”,
“environment”: “”,
“escalation”: “0”,
“upon_approval”: “proceed”,
“correlation_id”: “”,
“location”: “”
}
}

@c3f1e68294fdcf4a1f0a817ca

as per given data it is present only once and no array is present

once deserialized you can use the below to get requester_for info

jobj("result")("access_requested_for")("value").ToString

cheers

we are not sure if this is really meant

deserialize json - myJObject
grafik

retrieval all value:
grafik

Also the provided samples are looking different within the structure.

Another check you can do by:

myJObject.SelectTokens("..access_requested_for").Select(Function (x) x("value").Value(of String)).toArray
1 Like

Hi this is what I am looking for but I am getting only one value

{
“result”: {
“parent”: “”,
“made_sla”: “true”,
“watch_list”: “”,
“sn_esign_document”: “”,
“upon_reject”: “cancel”,
“sys_updated_on”: “2023-08-31 15:30:00”,
“task_effective_number”: “ACR012345”,
“approval_history”: “”,
“select_role”: “37bfe0bcc4bcbd8”,
“skills”: “”,
“number”: “ACR012345”,
“sys_updated_by”: “dummy_user”,
“opened_by”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/abcdef123456789”,
“value”: “abcdef123456789”
},
“user_input”: “”,
“sys_created_on”: “2023-08-31 10:00:00”,
“sys_domain”: {
“link”: “https://dummy-link.com/api/now/table/sys_user_group/global”,
“value”: “global”
},
“state”: “2”,
“access_requested_for”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/1234567890”,
“value”: “12890”
},
“route_reason”: “”,
“sys_created_by”: “dummy_creator”,
“order”: “”,
“access_requested_for”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/1234567890”,
“value”: “12345”
},
“closed_at”: “”,
“cmdb_ci”: “”,
“cmdb_ci_business_app”: “”,
“contract”: “”,
“impact”: “3”,
“active”: “true”,
“work_notes_list”: “”,
“business_service”: “”,
“priority”: “4”,
“sys_domain_path”: “/”,
“time_worked”: “”,
“expected_start”: “”,
“access_requested_for”: {
“link”: “https://dummy-link.com/api/now/table/sys_user/1234567890”,
“value”: “12890”
},
“opened_at”: “2023-08-31 09:45:00”,
“business_duration”: “”,
“group_list”: “”,
“work_end”: “”,
“approval_set”: “2023-08-31 15:45:00”,
“work_notes”: “”,
“request_access_to”: {
“link”: “https://dummy-link.com/api/now/table/x_amge2_access_app_access_listing/xyz987”,
“value”: “xyz987”
},
“universal_request”: “”,
“short_description”: “”,
“access_type”: “add”,
“correlation_display”: “”,
“work_start”: “”,
“assignment_group”: {
“link”: “https://dummy-link.com/api/now/table/sys_user_group/789abc”,
“value”: “789abc”
},
“additional_assignee_list”: “”,
“description”: “”,
“calendar_duration”: “”,
“close_notes”: “”,
“service_offering”: “”,
“sys_class_name”: “x_amge2_access_app_access_request”,
“closed_by”: “”,
“follow_up”: “”,
“sys_id”: “dummy_sys_id”,
“contact_type”: “self-service”,
“sn_esign_esignature_configuration”: “”,
“urgency”: “”,
“company”: “”,
“justification”: “Dummy justification text”,
“reassignment_count”: “0”,
“activity_due”: “”,
“assigned_to”: “”,
“comments”: “”,
“approval”: “approved”,
“sla_due”: “”,
“comments_and_work_notes”: “”,
“due_date”: “”,
“sys_mod_count”: “2”,
“sys_tags”: “”,
“environment”: “”,
“escalation”: “0”,
“upon_approval”: “proceed”,
“correlation_id”: “”,
“location”: “”
}
}

_test.xaml (13.4 KB)

your JSON is not correct and defines access_requested_for multiple times

You can check when validating it e.g. within https://jsonlint.com/

Therefore you will get only one value back

Thanks for your help. This is working.
One last doubt, how to write the same in C#

which statement was finally used?

myJObject.SelectTokens(“…access_requested_for”).Select(Function (x) x(“value”).Value(of String)).toArray

this one

give a try at

myJObject.SelectTokens("..access_requested_for").Select(x => x["value"].ToString()).ToArray();
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.