How can I fetch the output in json format from DAM parent node to certain level

Avatar

Avatar
Affirm 1
Employee
ashishg1547773
Employee

Like

1 like

Total Posts

4 posts

Correct reply

1 solution
Top badges earned
Affirm 1
Boost 1
View profile

Avatar
Affirm 1
Employee
ashishg1547773
Employee

Like

1 like

Total Posts

4 posts

Correct reply

1 solution
Top badges earned
Affirm 1
Boost 1
View profile
ashishg1547773
Employee

03-09-2020

I have requirement to get all the assets and its properties in .json format at certain level by URl as /content/dam/abc/a.1.json

I am able to get data using httpclient library by get call ,Is there any other way to fetch the data in json format as I don't want to pass username and password in get call

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Nupur_Jain
MVP

Likes

165 likes

Total Posts

186 posts

Correct reply

76 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Establish
MVP
Nupur_Jain
MVP

Likes

165 likes

Total Posts

186 posts

Correct reply

76 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile
Nupur_Jain
MVP

14-09-2020

Hi @ashishg1547773 

 

You can also use SlingRequestProcessor Library. It requires AEM system user to make a request similar to HTTP request. The system user must have access to path where you are making a request.

 

You can take a look at the sample code:

 

        String assetUrl = assetPath + ".1.json";
        HttpServletRequest request = requestResponseFactory.createRequest("GET", assetUrl);
        request.setAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME, WCMMode.DISABLED);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        HttpServletResponse response = requestResponseFactory.createResponse(out);
        try {
            requestProcessor.processRequest(request, response, resourceResolver);
            String jsonString = out.toString(HQConstants.UTF_8_ENCODING);
        } catch (ServletException | IOException e) {
        } 

 

Here, you need resourceResolver which must be of system user with right access rights. The above makes same request as HTTP request and as your requirment, does not need credentials.

 

Hope it helps!

Thanks!

Nupur 

Answers (0)