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?
That seems like compressed data. What happens if you leave the "Accept-Encoding" empty?
Tried doing that. Didn't work.
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
Oh yes, it was a type. But correcting that too, didn't work, is giving me the same junk/encoded result
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.
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
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.
How do i check which format is that in response, and how do you use that information to solve the issue?
Hello,
have you tried to decompress the response with this component?Gzip
On the component page you can even test the webservice.
Best regards,
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.
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:
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.
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.
Good suggestion. I didn't know about this feature.
This is also a good suggestion. I'l try them both.
Thanks,Rob
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
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?
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.
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?
It would be better if you put this question on the forum with a new post.
Put in a screenshot as well.
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
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.