cancel
Showing results for 
Search instead for 
Did you mean: 

Obtaining JSON data from a URL using HTTP GET

ritesh_a_ramkhe
Level 4
I am trying to develop a VBO which will use a HTTP GET request to obtain JSON data from a URL and then be able to store the JSON data as a collection so the different object values can be used for automation. Does anyone have any ideas as to how this can be done, or any examples which may help?
5 REPLIES 5

shahariar_k_bhu
Level 5
A simple way to obtain JSON data from a URL: -------------------------------------------------------------------------------------------- In: URL Out: Result (JSON data) Code stage VB.NET: Dim webClient As New System.Net.WebClient Result = webClient.DownloadString(URL) -------------------------------------------------------------------------------------------- Alternatively, you can use HttpWebRequest class in VB.net / C# to perform requests. HttpWebRequest is detailed at: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx JSON to Collection: Import JSON business object from C:\Program Files\Blue Prism Limited\Blue Prism Automate\VBO. Use Convert JSON to Collection or something action to translate the JSON data into a collection.

ritesh_a_ramkhe
Level 4
Thank you for your comment. I managed to get the JSON data into a text data item. However when the JSON to collection action stage is run, the following error appears: ""Internal : Could not run the object because one of the code stages has a compile error, use Check for Errors for a list of problems

ritesh_a_ramkhe
Level 4
Managed to sort the issue out by including Newtonsoft.Json.dll in the Blue Prism directory. However the resultant collection stores the values I need to extract in arrays of objects. Is there a way to extract particular values from an array within a collection?

shahariar_k_bhu
Level 5
JSON:Array in a collection is simply a collection, so you could loop through the main collection, and access the fields using their corresponding field name. For example: Loop over collection -> have a calculation stage where you have the expression: [Collection.JSON:Array.FIELDNAME] and store the result to a data text item. Or you could handle that part using code blocks, set the JSON collection as input with some filter criterias, and a filtered collection as output.

ritesh_a_ramkhe
Level 4
I tried it using the loop method you described above and it works as intended. Thanks for the help!