Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Experience fragment export as json to consume in third party application

Avatar

Level 4

Hello,

I am trying to expose experience fragment as JSON data where experience fragment has custom component. I can get the desired JSON with path http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master/jcr:conten... where globalnav is resource node name created for our custom component.

 

But my question is that resource node name may change if we reauthor the component & component resource may get different name like "globalnav_randomnumber". How can we get reliable resolver path to access JSON from third party in above scenario ?. @MihneaD @Jörg_Hoh 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

It doesnt make sense to expose http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master/jcr:conten... this link as a content server as it has jcr:content in it , also you are replying on the node formed by component. If someone removes the global nav component from the XF and readd and author it , then your content service will fail

 

Suggestion - to use Content service as  http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master.json --> to incorporate this do the necessary changes in the model

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @pradeepmoolemane 

Component name wont change for edit of same component unless you add the same component once again to the resposnive grid in that case for second one it will appear as componentname_numericidentifier eg: image_198892222

 

As per my understanding we can handle this using regular expression pattern for json variable at the third party consumer.

 

Regards,

Rajashankar.R

Avatar

Level 4

yes, with edit wont change node name. but if we think robust nature, author have option to delete & readd the component. So with this, component name can change at any point.

Avatar

Correct answer by
Community Advisor

It doesnt make sense to expose http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master/jcr:conten... this link as a content server as it has jcr:content in it , also you are replying on the node formed by component. If someone removes the global nav component from the XF and readd and author it , then your content service will fail

 

Suggestion - to use Content service as  http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master.json --> to incorporate this do the necessary changes in the model

Hi @SundeepKatepally thanks for your reply. with master.json, I get only injected node structure data and default structure. But we have some costume logic and consume json structure that wont come up with master.json or master.<depth>.json.

 

Can you please provide any reference example where we can get custom data as well.

and is there a way to restrict to add a component only once in a page ?

Avatar

Employee Advisor

You can register a custom script/servlet to the resourcetype "cq/experience-fragments/components/experiencefragment" using the selector "navigation", which then is able to provide you the required information. Then you can you use a request like

 

http://localhost:4502/content/experience-fragments/my-project/us/en/site/globalnav/master.navigation...

 

to retrieve the navigation stored at this XF. Content Services might be a good way as well, but it requires you to adjust your content structure a bit (having the navigation as a standalone fragment).