API call response - JSON downlading | Community
Skip to main content
Tanmay137
Level 2
Feb 21, 2019 4:02 PM UTC
Solved

API call response - JSON downlading

Hello everyone,

We have an API service, when I use it to get a JSON response in the browser. The file is downloading instead of displaying in browser?

It is happening on only localhost and Publish environment. It works perfectly on Author.

Is there any configuration settings I need to change to restrict the JSON from being downloading?

Thanks

Tanmay

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Feb 21, 2019 4:21 PM UTC

Hi,

Please make sure when your API returns response, it should set below response header in order to display JSON

Content-Type: application/json; charset=UTF-8

Arun Patidar

6 replies

Tanmay137
Tanmay137Author
Level 2
Feb 21, 2019 9:10 PM UTC

It worked, Thank you Arun.

Translate
Gaurav-Behl
Level 10
Feb 21, 2019 5:24 PM UTC

Content-Disposition - HTTP | MDN  says  In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.

Hence, check the request headers and also check Apache Sling Content Disposition Filter configuration in /system/console/configMgr or it could be somewhere in your code or specific browser behavior.

Translate
smacdonald2008
Level 10
Feb 21, 2019 4:41 PM UTC

See Arun suggestion.

Also - in a use case we have in an article,  - we make a call to a service that returns JSON. We then parse the JSON and set our Java's data members and then display the data in a HTL component's view. At no point - is the JSON downloaded. See:

Creating an Adobe Experience Manager 6.4 HTL Component that displays data from a Restful Web Service 

Translate
Tanmay137
Tanmay137Author
Level 2
Feb 21, 2019 4:21 PM UTC

Thank for your quick response.

We are writing a servlet and exposing the endpoints. It a custom service created using Java and yes, are are parsing the JSON.

To add further to my question, we get a response when I hit the endpoint Author URL, when I try to hit the same using postman, we don't get any response.

Publish and Localhost URL just download the JSON file.

Thank you

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Feb 21, 2019 4:21 PM UTC

Hi,

Please make sure when your API returns response, it should set below response header in order to display JSON

Content-Type: application/json; charset=UTF-8

Translate
Arun Patidar
smacdonald2008
Level 10
Feb 21, 2019 4:11 PM UTC

In your AEM Service - how are you getting the JSON - are you calling another service that returns JSON. Are you then parsing the JSON? Is this a custom service that you created using Java?

Translate