Data Action - Array Output contract

[
  {
    "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.

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

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

1 Like

Hi @mikehardie ,
On using the above, I am getting error -> Expected ',' instead of 'j'

Hi @Jason_Mathison ,
Can you provide some details about how can I change my output to be an object?

I updated the example above to use code formatting (Highlighted the configuration and hit the </> button)

See if that works better.

--Jason

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