REST - Same TAG different Type

REST - Same TAG different Type

  

Hi,

Im try integrate Redmine Rest Api and in the response im have 2 different types in the same block for field value.


Ex: 

"custom_fields": [
        {
          "id": 7,
          "name": "Cliente",
          "value": "Alcon"
        },

       {
          "id": 44,
          "name": "Produto",
          "multiple": true,
          "value": [
            "Premium",
            "Custom"
          ]
        }

]


So my structure Data Type for field value change, same time is text same time is Text List, and im get erro.

Att,

Rafael Freitas

Solution

Hello Rafael,


This is a problem with REST API, as there is no "formal contract". While I think exposing a REST webserver that can change the Data Type for the same attribute is very bad practice, this happens a lot.


In general, to solve this, what you do is to use the OnAfterResponse to manipulate the response before it is delivered as a structure/list.


In your case, I would say that you must discover what data types are possible and change your structure to have all of them, and in the OnAfterResponse you manipulate the JSON changing the name of the attribute to match the correct type in the structure.


I know that it seems a lot of work, but I think this is the only way to do that (easily).

https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/REST/Consume_REST_APIs/Simple_Customizations

Solution