consume web service response's header with different data structures

consume web service response's header with different data structures

  

Hi there,

I have a case, when a respond is correct status = 200, the web service respond a structure like this in the body:

{

result:{

name:,

age,...

}

}


However when it is error, it responds with other structure:

{

errorcode:,

errorname:

}

My question is how to accomodate both structures in consuming that external REST using Outsystems. 

regards and thank you

Hi Pasar,

I am not sure but you could try something like this. 

-Hitesh-

Solution

Hi Pasar,

You could just add the errocode and errorname to the main structure. The Platform only parses what's in the JSON, and checks the JSON tags against the Attrbutes of the structure.

However, if the response is not something in the 200 range, you'll get an exception, and iirc, this means the response isn't parsed at all. You can change the result code in the On After Response to avoid that.

Solution

I found this: 

https://www.outsystems.com/forums/discussion/26455/get-the-http-status-code-returned-by-a-failed-consumed-rest-web-service/

Yeah, that's a good thread as well.