04-05-23 03:58 PM
Hi,
It's been a while since I used the product and am getting back in the swing of things, so please forgive a somewhat newbie's question.
I have a few REST API's with JSON body and output. I have one working just fine, thanks to some tips I found on this site. What isn't working is repeating content - something like this for multiple email addresses and multiple phone numbers that have country, phone and extension.
"my:to_EmailAddress": {
"my:results_2": {
"my:Repeating_Content": [
{
"my:to_EmailAddress_results_EmailAddress": "[inEmailAddress]"
}
]
}
},
"my:to_PhoneNumber": {
"my:results_3": {
"my:Repeating_Content": [
{
"my:to_PhoneNumber_results_DestinationLocationCountry": "[inCountryCode]",
"my:to_PhoneNumber_results_PhoneNumber": "[inPhoneNumber]",
"my:to_PhoneNumber_results_PhoneNumberExtension": "[inPhoneExtension]"
}
]
}
}
I thought I could specify these API parameters as collections
and then create collections in my process
and map them to the API parameters matching the field names in my JSON
But it doesn't work.
If I run without the collections, the API call works fine, but those fields with repeating values get a literal value of "<collection />", like email.
With it the collections mapped like above, the API call doesn't even run. I get a system exception, but no info on how to fix it.
Can someone please point me in the right direction? I think I'm close - just need repeating content in the JSON to be passed in properly.
TIA
Sigrid
04-05-23 05:27 PM
@SigridKok
So this is a Web API Service definition that you've created in Blue Prism with Collection as the data type for two of the input parameters, correct? I believe you'll need to set your Body Type to Custom Code and then write some C#/VB to iterate over the input Collections and create the necessary JSON content from it. Alternatively, you might be able to create custom object definitions in the Global Code section that use List<T> as the type for those Collections and then use Newtonsoft to generate the JSON body.
Cheers,
04-05-23 07:43 PM
Thanks, Eric.
I had a feeling it might not be simple, and custom code/objects is not ideal, especially if the API call JSON contents change.
Having said that, do you know of any examples for either/both of the approaches you shared above?
Thanks again,
Sigrid
04-05-23 08:28 PM
Hi @SigridKok ,
Try by removing the empty rows in the collections. There might be data validation in the API which has the fields as required fields because of which it might be failing (this is an assumption).
04-05-23 10:45 PM
Thanks, Babjee.
There aren't any blanks rows in the collections. I wish it was that easy! 🙂
Best Regards,
Sigrid
05-05-23 05:26 PM
Hi Sigrid Kok,
Below assets might be handy to write C# or vb.net . As mentioned you might need to write custom code either in C#/vb.net
I have done some thing similar in the past by using "Function for JSON manipulation(Custom C#)"
1) https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---json
2) https://digitalexchange.blueprism.com/dx/entry/7888/solution/json-manipulation-c
3) https://digitalexchange.blueprism.com/dx/entry/122702/solution/coremoran---utility---json
06-05-23 12:25 AM
Thanks @Harish M, I will check it out.
Best Regards,
Sigrid