70
Views
5
Comments
Fetch data from a REST API which returns an array of strings
Application Type
Reactive

I want to fetch data from a REST API which returns response as an array of strings. The REST API URL is:

https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search?sf=code,name&terms=tuberc 

and the returned response is 

[71,["A15.0","A15.4","A15.5","A15.6","A15.7","A15.8","A15.9"],null,[["A15.0","Tuberculosis of lung"], ["A15.4","Tuberculosis of intrathoracic lymph nodes"],["A15.5","Tuberculosis of larynx, trachea and bronchus"],["A15.6","Tuberculous pleurisy"], ["A15.7","Primary respiratory tuberculosis"],["A15.8","Other respiratory tuberculosis"],["A15.9","Respiratory tuberculosis unspecified"]]] 

which is not in JSON, I guess. I am a beginner in outsystems. So please help me out.

For more details, the website is 

https://clinicaltables.nlm.nih.gov/apidoc/icd10cm/v3/doc.html#output

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

That's indeed not valid JSON, but also it doesn't seem a REST API. Personally I'd use a GetRequest_Submit from the HTTPRequestHandler extension and process the output yourself.

UserImage.jpg
Aman Pandey

Hi Kilian,

Thank you for the response. 

I tried GetRequest_Submit HTTPRequestHandler extension but processing the data is bit difficult as the response won't always be same. I have to make different API calls every time and btw how can we access each character of response text inside a for each loop?

If I can access each character using for each loop, then data processing would be easier.

Thanks and regards

Aman Pandey

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Aman,

Yeah, processing such text is a bit of a pain in OutSystems. Personally I'd create an extension in C# to do that. You could use Substr to get each character, but again, I wouldn't do it in OutSystems. C# is way better for handling such things.

UserImage.jpg
Aman Pandey

Now I am getting a part of response as key value, but i am still not able to find a perfect solution. I have attached the below JSON and on jsonlint, it is indeed a valid JSON. How to access this API response now?


Query.txt
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Aman,

It's valid JSON, but not JSON that the Platform / Service Studio can handle, as the outer structure is an array containing different types (an integer, a text array, an object, and an array of text arrays). Also they're all nameless. It's pretty outlandish JSON tbh...

You'll have to do quite some post-processing to make sense of this, especially if that outer array can indeed contain a random collection of other data types.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.