Consume REST Api with a dynamic list inside one object

Hi everyone,

I´m new to OutSystems and trying to consume a REST Api with a dynamic structure.

The response looks like this

{

  "terminalCode": 80123456,

  "teuAll": 119,

  "hours": {

   "202007150600": 7,

   "202007150700": 4,

   "202007150800": 11,

   "202007150830": 2

  }

}

Inside the "hours" object the attributes name are dynamic and can not be defined because they are kind of dateTime values. Also the number of attributes can change for each request.

Any idea on how to solve the problem?


Thanks and best regards,

Mathias

Hello Mathias,

Hope you are doing well.

What is exactly the error / issue that you are facing when you consume the REST API?


Kind regards,

Rui Barradas

Hi Mathias,

When consuming a REST API within OutSystems, the JSON can't have dynamic attributes - the response must be predictable and fit within an expected structure. No errors will be raised, but the platform will be unable to map values to their expected attributes if they change on every request.

I believe that for these sorts of APIs, you'll need to create an Extension and consume them there.

Hi Rui,

thanks for the quick response.

The time I built the consume of the REST Api there were 2 structures created by OutSystems. First is for the overall information with terminalCode and TeuALL (that works perfectly) and additionally the list for hours. For Hours there is a second structure with Attribute 1 to xx. 

At the moment the response for the first line, attribute name (202007150600) and the value (7) only works if the first attribute name is 202007150600. Currently I only get the value 7 if it fits to the entry in the json. 

But what I want is that every line inside the "hours" object will be stored with the attributes name and the value.

Best regards,

Mathias

Solution

Hi everyone,

I was able to solve the problem by consuming the webservices as plain text and then using "ardoJSON". The attributes are then "converted" to key and value. With JSON Deserialize I know receive the structure I needed.

Thanks for your quick responses.

Best regards,
Mathias

Solution