cancel
Showing results for 
Search instead for 
Did you mean: 

REST API JSON with repeating content

SigridKok
Level 2

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
28678.png
and then create collections in my process
28679.png28680.png

and map them to the API parameters matching the field names in my JSON  
28681.pngBut 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



------------------------------
Sigrid Kok
PSE
Winshuttle
America/Los_Angeles
------------------------------
6 REPLIES 6

ewilson
Staff
Staff

@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,
 



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

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



------------------------------
Sigrid Kok
PSE
Winshuttle
America/Los_Angeles
------------------------------

Babjee24
Level 7

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).



------------------------------
Babjee Vangipurapu
Senior RPA Developer
Wonderbotz
India
------------------------------
Babjee Vangipurapu
Senior RPA Developer
India

Thanks, Babjee.

There aren't any blanks rows in the collections.  I wish it was that easy! 🙂

Best Regards,
Sigrid



------------------------------
Sigrid Kok
PSE
Winshuttle
America/Los_Angeles
------------------------------

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



------------------------------
-----------------------
If I answered your query. Please mark it as the "Best Answer"

Harish M
Lead developer
America/New_York TX
------------------------------
----------------------- If I answered your query. Please mark it as the "Best Answer" [FirstName] [LastName] [Designation] [JobTitle] [City] [State] [Phone]

Thanks @Harish M, I will check it out.

Best Regards,
Sigrid



------------------------------
Sigrid Kok
PSE
Winshuttle
America/Los_Angeles
------------------------------