Custom Request Payload for REST activity with JSON array
I have an eForm that I am using to send a request to a REST API. Within the REST activity, I am able to map all the fields using the request payload configuration (map payload with schema) except for the choice field used in the eForm. The REST API request is expecting an array for this field when more than one choice is selected. This is the JSON for one item:
"lstTypes": [
{
"CategoryType": "Type1_Value"
}
]
If there are more choices selected then the JSON looks at this:
"lstTypes": [
{
"CategoryType": "Type1_Value"
},
{
"CategoryType": "Type_Value"
}
]
I tried using c# with the custom data conversion but that doesn't allow me to modify the JSON request. Is there a way to do this? I could build a custom payload using Javascript or c# but I can't find a way to do that. Any help would be appreciated.
Thanks,
Eddie
-
Hi Harish, thanks for your response. In the sample payload, when I use this in my JSON array:
"lstTypes": [
{"CategoryType": " " },
{ "CategoryType": " " }
]The mapping only detects one item in the array.
The choice field has the data separated by a semicolon. I can use the custom data conversion to parse out the data but I'm not sure how to map that into the array. I hope I'm explaining this ok.
Thanks again for your help,
Eddie
-
That is correct Eddie. It will only show 'CategoryType' once. Since it gets detected as repeating the runtime part is capable of producing any number of lstTypes array items.
Note: I noticed that your have not mapped istTypes to right side data properties. that is mandatory for repeating to work.
Regarding custom data conversion to convert semicolon separated data to an JSON array, I think 'SelectedTypeofTechnology' is the choice filed which are you referring to. Am I correct?
It seems to be complex and I have not seen the possibility of doing such conversion using the OOTB features. I will let you know if I come up with something that will help you.
Have you considered any alternatives outside of custom conversion where you have more control of the data and it's structure?
Regards,
Harish
-
Hi Harish, your feedback was helpful. I was able to get this to work by using a dropdown field within a repeatable subform and mapping that to the JSON array. Using a drop-down field is not the most user friendly though. Is there a way to use the checkbox field with this approach?
I'm new to AgilePoint so I'm not familiar with other alternative that would give me more control. I would like to explore this option. I have 2 repeatable sub-forms now that I will need control how this data gets passed to the API. Is there some documentation that can help understand these alternatives?
Thanks for your continued support here.
Eddie
-
Hi Harish, below is the request and response structure. My eForm has a repeatable subform with a nested repeatable subform to hold the types.
Request Type:
{
"PtNumber": "postmanTestD_20201113",
"IsTA": "false",
"BusinessUnit": "IAS",
"FunctionalArea": "IAS-PR",
"Revision": "5",
"UserID": "M123456",
"lstTypes": [
{ "CategoryType": "Type 1" },
{ "CategoryType": "Type 2" },
{ "CategoryType": "Type 3" }
]
}Response Example:
{
"Status": "FAILED",
"Message": "Category type 1 : should not be empty",
"Data": null,
"ExceptionCode": 0
}Thanks again for your help
Please sign in to leave a comment.
Comments
6 comments