GoyalAAakanksha | 2022-09-12 15:53:22 UTC | #1
I would like to supply the following as the request body template of a POST Request Data Action-
{ "action": "accountRequest", "accountRequest": { "accs": [{ "accnumber": "999999999999", "currency": "EUR", "code": "01" }, { "accnumber": "888888888888", "currency": "EUR", "code": "02" }], "balanceTypes": null } }
Now, number of accounts is variable for each request, is there any way to handle this and write a configuration? I am supplying two comma separated lists from architect as Input contracts, one containing the accnumber, another one containing the code.
I have gone through existing articles and velocity macros to achieve this, but not able to find a solution. Tried to create the arrays with the comma separated list using -
set($AcconutNumberArray=$input.AccNumber-List.split("\,"))
set($AdminCodeArray=$input.Code-List.split("\,"))
and then use the #foreach loop to retrieve the elements, however I can only run the loop with one set of array, so it's not possible to provide corresponding index values of account number and the code to the request body.
Please let me know if there is any way around it.
Thank you in advance, Aakanksha
Jason_Mathison | 2022-09-12 16:19:08 UTC | #2
Hi Aakanksha.
Is there a reasonable upper bound on the number of accounts that you have to support, or does it have to support any number?
--Jason
Jason_Mathison | 2022-09-12 18:19:51 UTC | #3
Here is an approach that you can take where you can handle as many accounts as you want:
set($AcconutNumberArray=$input.AccNumber-List.split(","))
set($AdminCodeArray=$input.Code-List.split(","))
{ "action": "accountRequest", "accountRequest": { "accs": [{ "accnumber": "${AcconutNumberArray[0]}", "currency": "EUR", "code": "${AdminCodeArray[0]}" }
if ( $AcconutNumberArray.size() > 1)
, {"accnumber": "${AcconutNumberArray[1]}", "currency": "EUR", "code": "${AdminCodeArray[1]}"}
end
if ( $AcconutNumberArray.size() > 2)
, {"accnumber": "${AcconutNumberArray[2]}", "currency": "EUR", "code": "${AdminCodeArray[2]}"}
end
],"balanceTypes": null}}
It assumes that your account number and admin code lists will be the same length and will always include at least one item.
--Jason
GoyalAAakanksha | 2022-09-12 19:44:51 UTC | #4
Thank you Jason, this is really helpful! I don't know yet if there is an upper limit we can set on the number of accounts , gonna check it tomorrow with the business.
John_Carnell | 2022-09-16 12:36:17 UTC | #5
This post was migrated from the old Developer Forum.
ref: 16246