API Response Does Not Match Manual Call

Hello all,

I'm trying to set up a simple app that simple takes a date range, makes an API call to NASA's NEO project, and return select information about near earth objects that were detected on within the date range. 

Because the API response separates the lists of objects by date if multiple days are selected, my logic is currently taking the date range a user gives and iterates through the days, making separate API calls for each day.

Even using this approach, however, I am getting poor results.  If you request the period from 6/30 to 6/30, for example, you get an empty list.  In debugging, I can see that the api call is made, and I know that if I send the from the method itself I can see the expected response.  I cannot figure out what is going on.

Any help would be greatly appreciated.

The issue here is the JSON. For Outsystems to parse the data correctly, the JSON structure needs to match.

The specific problem is highlighted in the following image:

The attribute name is a variable value. OutSystems does not cater for this. What you will need to do is to add an attribute with a NameInJSON value for each of the dates you could potentially encounter, i.e. as in the following image:

You should be able to see results for June 30, 2019, July 1, 2019, and July 2, 2019.

That explains so much, I should be able to avoid the weird loop I put in to.  Thanks so much.

Hanno wrote:

The issue here is the JSON. For Outsystems to parse the data correctly, the JSON structure needs to match.

The specific problem is highlighted in the following image:

The attribute name is a variable value. OutSystems does not cater for this. What you will need to do is to add an attribute with a NameInJSON value for each of the dates you could potentially encounter, i.e. as in the following image:

You should be able to see results for June 30, 2019, July 1, 2019, and July 2, 2019.



No worries! Hope you get it working

Jhonatan Melo wrote:

https://jsonlint.com/

https://www.getpostman.com/

Dude, just posting links doesn't help. At least make some effort to explain how the content in the link you provided will help.


Hanno wrote:

Jhonatan Melo wrote:

https://jsonlint.com/

https://www.getpostman.com/

Dude, just posting links doesn't help. At least make some effort to explain how the content in the link you provided will help.


https://jsonlint.com/ - JSONLint is a web based tool to validate JSON String/Object. After validate, Json Validator tool helps you to share your json data.

https://www.getpostman.com/ - is a tool used to send requests and receive responses through our REST API, but instead of relying on curl, you can instead use a dedicated app interface to organize and save your tests.


Are tools I use to validate when I have difficulty debugging json errors


Thank you, Jhonatan. That makes more sense and anyone reading the post that is not familiar with those tools will now understand the relevance of your post!

Hanno wrote:

The issue here is the JSON. For Outsystems to parse the data correctly, the JSON structure needs to match.

<.. snip ..>

You should be able to see results for June 30, 2019, July 1, 2019, and July 2, 2019.

Although this is probably the solution for this problem in OutSystems I don't see how I can implement this in a practical manner. Take the date range for example, There are 365 days per year and many more years. If I want to make such api history- and future proof then simply creating additional attributes isn't going to cut it. The possible number of dates are endless and adding those manually, that is an impossible task. 

In c# I think I would have solved this with a dictionary <string><object> but as far as I know this is not possible in OutSystems, or is it?

Would there be other methods to solve this problem? 


Solution

Hi Heath,

the solution so you would only have to define a single structure (called Attribute1 in your oml, but i named it objectlist) is to change the json returned from the api call before the Outsystems parsing is executed.  You can do this by creating an OnAfterResponse Event on the NASA Api, and replace the attribute with the date as a name, by whatever name you defined in the structure.  You can use Regex for this.  I tried this out, see attached OML.


So :

1) choose the name you like for the list of near earth objects:

I leave 'Name in JSON' empty, if you put something in here, that's what you'll need to match in the Regex Replace

2) Add an OnAfterResponse EventHandler to the NASA REST API


3) In the OnAfterResponse, run a Regex_Replace, replacing the date in the output, by whatever you chose in step 1 as the attributename (in my case 'objectlist')  That means the Outsystems parser will only ever get to see the 'objectlist' node, not the ever changing date nodes.




I'm no hero with this Regex stuff, there's probably better ways of doing it, but this works.  You will probably first have to go to dependency management and find Regex_Replace in the Text extension.


Good luck,

Dorine


Solution

Nice solution Dorine!