Shubham_Bhosale | 2024-07-16 16:03:23 UTC | #1
[
{
"userId": "userId1",
"source": "PURECLOUD",
"presenceDefinition": {
"id": "6a3af858-942f-489d-9700-5f9dcdae9b",
"systemPresence": "Available",
"selfUri": "/api/v2/presencedefinitions/6a3af858-942f-489d-9700-5f9dcdae9b"
},
"message": "",
"modifiedDate": "2024-07-16T11:40:22.935Z",
"selfUri": "/api/v2/users/userId1/presences"
},
{
"userId": "userId2",
"source": "PURECLOUD",
"presenceDefinition": {
"id": "e08eaf1b-ee47-4fa9-a231-12e284798f",
"systemPresence": "On Queue",
"selfUri": "/api/v2/presencedefinitions/e08eaf1b-ee47-4fa9-a231-12e284798f"
},
"message": "",
"modifiedDate": "2024-07-16T09:49:44.149Z",
"selfUri": "/api/v2/users/userId2/presences"
}
]
I'm receiving the API response for two users as described above, and I need to fetch details for 'n' number of users. In the data action, I want to modify my output contract to retrieve only the 'userId' and 'systemPresence' fields. Since the API response is in array format, I am currently able to get the desired output for a single userId (output contract for single userId request is shown below). However, when multiple userId's are passed, I am unable to get the output correctly.
Jason_Mathison | 2024-07-16 16:07:02 UTC | #2
You could change your output to be an object that hold 2 arrays of strings.
You can gather the user Ids with a templateMap of *.userId
and the system Presence values with *.presenceDefinition.systemPresence
--Jason
mikehardie | 2024-07-30 16:00:31 UTC | #3
Another option is to return it a a stringified JSON object and then convert it back to JSON with the callflow. You can then iterate throughthe object getting the bits you required.
{
"translationMap": {
"res": "$"
},
"translationMapDefaults": {},
"successTemplate": "{\"jString\": \"$esc.jsonString(${res})\"}"
}
Note backslashes are removed so add backslash"j and backslash"}
Shubham_Bhosale | 2024-07-17 06:48:51 UTC | #4
Hi @mikehardie , On using the above, I am getting error -> Expected ',' instead of 'j'
Shubham_Bhosale | 2024-07-17 09:16:24 UTC | #5
Hi @Jason_Mathison , Can you provide some details about how can I change my output to be an object?
Jason_Mathison | 2024-07-30 16:01:26 UTC | #6
I updated the example above to use code formatting (Highlighted the configuration and hit the </> button)
See if that works better.
--Jason
system | 2024-08-30 16:02:04 UTC | #7
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 27261