I would start by posting a bug ticket to that endpoint for being poorly behaved! It seems like it should always return an array, even if it is a single error.
If the response is being returned to Architect I would probably handle this special case there, as it has JSON tooling that can attempt both the single response and array response. While cleaning this up in a data action might be possible, it is going to be some pretty ugly string manipulation.
------------------------------
--Jason
------------------------------
Original Message:
Sent: 04-22-2025 12:16
From: Alex Kolath
Subject: Response template for dynamic responses
I have a Data Action that makes an API request. In error scenarios on the API, it returns either:
"errors" : {
"error": {
"key": "key 1",
"value": "value 1"
}
}
But if there are 2+ errors, "error" turns into an array:
"errors": {
"error": [
{
"key": "key 1",
"value": "value 1"
},
{
"key": "key 2",
"value": "value 2"
}
]
}
I have the Response Contract to accept the array. How can I make the template such that if I have a singular error object (no Array), I can place it in the array of the contract? And if the response is an array, it populates normally.
#DataActions
------------------------------
-
------------------------------