386
Views
22
Comments
Consuming Rest API : problem with response body

Hi 

I am Using "Consume Rest API" for a particular URL and giving required headers and request body.

However, I am receiving junk/encrypted response as shown in screenshot below.

The same is giving correct result when tried in Postman.

Any suggestion?


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

That seems like compressed data. What happens if you leave the "Accept-Encoding" empty?

UserImage.jpg
Rakhi Gupta

Tried doing that. Didn't work.

2021-08-12 11-00-27
Nordin Ahdi
 
MVP

Hi Rakhi,

Just something I noticed. I see a typo in the Accept header field. 

It says applications/json where it should be application/json.

Regards,

Nordin

UserImage.jpg
Rakhi Gupta

Oh yes, it was a type. But correcting that too, didn't work, is giving me the same junk/encoded result

2020-09-01 10-42-42
Stefano Valente

did you make any progress with your issue?


To me it seems like your encoding is wrong. Possibly it could be compressing, as Kilian mentioned.

first thing to do is to have a look what SOAP UI or another webservice tool returns.



2020-09-18 09-37-36
Devendra Baghel

Hi Rakhi,

As  the Rest API has accept encoding as "gzip deflate" the data coming from the server is in compressed format and at the client the data should be decompressed.  In the Test tab of API you are seeing the compressed data however if you get the response from Postman you can paste the response in Body tab that would generate the necessary Structures  refer the attached screen shot.

Postman does this decompression may be outsystems  Test tab currently doesn't support the decompression but the compressed API's works fine by just adding the response in Response tab.

Best Regards

Devendra Baghel


response.PNG
2026-02-05 15-36-36
Lenon Manhães Villeth
Champion

Hi, friend. 

I faced something like that with an API that was responsing a binary file. You need ti check wich format is that in response.

UserImage.jpg
Matthew Vines

How do i check which format is that in response, and how do you use that information to solve the issue?

2021-11-19 11-12-44
Rui Mendes

Hello,

have you tried to decompress the response with this component?
Gzip

On the component page you can even test the webservice.

Best regards,

UserImage.jpg
Robert Adams

Great component, Rui. Unfortunately, because this can obly be applied at OnAfterResponse, the compound structure that us usually auto-created using the JSON Response format will not work because at the test stage it has not been decompressed. There should be a better way that OutSystems handles the auto generation of these structures. I have a very complex JSON structure and creating it manually is going to be very difficult and time consuming.  

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Robert,

Two thoughts: one, compressed REST response is very rare, and kinda useless, as HTTP(S) communication is typically already compressed. I've never seen compressed REST responses in the wild myself (and I've consumed a fair bit of them). So I can fully understand OS not supporting this out of the box. Two, if you already have the JSON of the response, you can use the "Add Structure from JSON..." command, which you can access via the context menu of the Structures folder in the Data tab:

2021-11-19 11-12-44
Rui Mendes

As you said if the json structure is too complex to be handled by the OustSystems automatism and also too much to be written by hand, I suggest that you use some SOAP service tool such as SoapUi to assemble a clone of the service and there you can export the Json structure, which should be placed in OutSystem as Kilian shown.

Another way will be to use some site that converts the response into json.

Good luck in your task.



2021-11-19 11-12-44
Rui Mendes

I remembered that if you use the test page of the component you have access to the answer, In OustSystems you will configure a new service (dummy) and put in the answer the same that you received in the test page of the component.

This new service will not work, but it will generate the structure for you to use in the original.

UserImage.jpg
Robert Adams

Good suggestion. I didn't know about this feature.

UserImage.jpg
Robert Adams

This is also a good suggestion. I'l try them both.


Thanks,
Rob

UserImage.jpg
Matthew Vines

This worked for me by putting the gzip decompress action in the API OnAfterFetch, inputting the response binary, and setting the customized response text to the gzip output

2021-09-08 08-01-41
Lorena Sabou

Hey Matthew, I'm trying to do the same now but I keep receiving System.IO.InvalidDataException: Found invalid data while decoding. Have you experienced this? 

Is the response of your API defined as a JSON, or binary?

UserImage.jpg
Matthew Vines

I have not experienced that error. The response of my API is defined as a gzip compressed json, but it also returns binary data. That binary data can be put into the gzip decompress actions to return a json string. I might be able to help if you provide the API you're using or, even better, an oml file.

2023-09-15 07-07-52
Thomas Ng

Hey All, I tried to consume an endpoint as well however the copy response to body button is greyed out eventhough the response is 200 OK, why is that?

2020-09-01 10-42-42
Stefano Valente

It would be better if you put this question on the forum with a new post.

Put in a screenshot as well. 

2024-02-22 15-41-45
Trương A Xin

This is binary data (gzip) return from a API

You can setup to decompress it in OnAfterRequest by using this forge Gzip Compress/Decompress.

About generating structure in OutSystems automatically, you can use Postman to call that API, Postman will convert response from gzip content automatically in JSON content. Then you have to copy that JSON in to response then click on Finish button.

Note that after decompressing in OnAfterRequest, you have to assign the decompressed data to ResponseText and ResponseBinary.

Refer to: REST Callback Action OnBeforeRequest/OnAfterRequest

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Trương,

The original question is from 2021, the last reply is from 2022. Please check the dates of a post before you reply - replying to such old posts is of no use to anyone. Thanks.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.