Hello, I have an external API where it return response with multiple duplicated keys. How do I handle this? For now, the Outsystem will take only 1 latest value an insert into the response data type in Outsystem. So, for example, the response will be:
But the Outsystem will only saved the response as:
I want it to be as below:
Hi,
Is your response is List or Record?
Can you share the screenshot of the response?
Regards,
Wasimkhan S
Hi Muhammad,
that is not a well designed JSON, a key by definition should probably be unique to make sure everyone can work with the JSON correctly.
That being said, it is technically possible, so you might be in a situation that you can't control the provider of the api.
In that case, you'll have to preprocess the JSON before outsystems ingests it. This would typically be done in the OnAfterResponse of an api.
You will have to do text manipulations there to make it ingestable, either by turning the object into an array (which to me, it feels like that is what it is anyway), or by giving them unique names (complicated if there is no upper limit to the number of 'name' keys in a single object).
Hello Dorine, yes it is not well designed JSON as I can't control the provider of the api. Based on your reply, how do we do text manipulations in the event "OnAfterResponse"?
you can use just any server side text functions on the ResponseText.
depends on how you define the response in your api method output parameter. For example, if you want to get a list of names, you'd have to turn the object in to an array, meaning replacing the outer parenthesis by square brackets.
Hi ,
In addition to above answers,
You need to customise response of an API on the OnAfterResponse.
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/expose_rest_apis/customize_rest_api_responses/
You can loop through the response list and find out unique values pair and then save it accordingly as per your need.
Thanks.