Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

how to fetch json file from DAM and use it in HTL file in JavaScript in AEM as a cloud service

Avatar

Level 5

I have an json file located in DAM path .

I want that file to be picked and I am using the content of JSON file to display dropdown

 

I am able to achieve it in the author instance but I am not able to fetch JSON file in publish instance 

 

Here is the code : 

 

 

jQuery.getJSON('/content/dam/psg/hydro/listofChemicals.json', function (data) {
          productSelectorChemicalList = data.chemicals;
}
 
I am using the data from json file to make a dropdown , I am able to fetch and do it in author instance but unable to do it in publish instance, can anyone help me out here
 
what I am doing wrong and how can I fix it .
 
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

I'm glad this helped to find the root cause.

 

For the documentation around the filtering on the dispatcher take a look here:-

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-c...

 

For a working example, you can refer to the wknd GitHub implementation,

https://github.com/adobe/aem-guides-wknd/blob/main/dispatcher/src/conf.dispatcher.d/filters/default_... 

it's not valid for this use case but also as a reference to your other implementation of AEM as Cloud based project. It's updated from time to time with new features implementation.

 

Something like this in your case:-

 

/0020 { /type "allow" /url "/content/dam/psg/hydro/listofChemicals.json" }

 

or a more generic one (recommended as it restricts the pattern)

/0034 { /type "allow" /path "<your path(s)>" /method "GET" /extension '(json)'}

 

Hope this helps!

 

Regards,

Nitesh

 

View solution in original post

9 Replies

Avatar

Community Advisor

Hi,

In Publish instance check the access of DAM file? better to write some logs and check error logs.



Arun Patidar

Avatar

Level 5

Hi @arunpatidar 

Thank you for your response

No I am not able to access DAM file in publish instance , it's throwing 404 error.

Avatar

Employee Advisor

Hi @rahul234dabas ,

 

Since this is an ajax call, check what error you see in-network tab.

Also, since this is AEM as Cloud implementation check your dispatcher rules if the JSON is allowed to be served. If yes then check if it's blocked for this path.

 

Hope this helps!

 

Regards,

Nitesh

 

Avatar

Level 5

Hi, @nitesh_kumar 

Thank you for you response , seems like the dispacher rule is not written to allow json files , may I know how to write a rule to include json files?

Avatar

Correct answer by
Employee Advisor

I'm glad this helped to find the root cause.

 

For the documentation around the filtering on the dispatcher take a look here:-

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-c...

 

For a working example, you can refer to the wknd GitHub implementation,

https://github.com/adobe/aem-guides-wknd/blob/main/dispatcher/src/conf.dispatcher.d/filters/default_... 

it's not valid for this use case but also as a reference to your other implementation of AEM as Cloud based project. It's updated from time to time with new features implementation.

 

Something like this in your case:-

 

/0020 { /type "allow" /url "/content/dam/psg/hydro/listofChemicals.json" }

 

or a more generic one (recommended as it restricts the pattern)

/0034 { /type "allow" /path "<your path(s)>" /method "GET" /extension '(json)'}

 

Hope this helps!

 

Regards,

Nitesh

 

Avatar

Community Advisor

HI @rahul234dabas ,

There can be multiple reasons for this issue

  1. File is not available in AEM publisher instance.
    Verify if you can access the file in publisher instance by opening the file URL in browser directly.
  2. File is not allowed by dispatcher rule.
    check the relative farm file and look for filters, verify if the file has been allowed or not.
  3. Check logs, if there is any issue in the network tab.

I hope it helps.

 

Thanks,

Rohit

Avatar

Employee Advisor

It could be in error due to various reasons

 

1. Not published - you need to publish the JSON file and verify you can see them in publisher. Based on your replication config, there is a chance that its blocked there

2. Dispatcher filters - Like Arun mentioned, unless you allow JSON file access, it will be blocked. So need to ensure you have a valid rule to allow this file in JSON 

3. URL rewriting - Based on how your URL rewriting definitions are, that can also pollute your request. If your /content/dam/ path is trimmed for better URL paths in the webserver, there is a chance /content/ is not allowed. Ensure this path is accessible OR update your JS to have a publisher calling path like your rule

Avatar

Employee

Hi @rahul234dabas ,

 

Coud you please check if the path is present in "/content/dam/psg/hydro/listofChemicals.json" this needs to be replicated.

 

Post you need to allow "'/content/dam/psg/hydro/listofChemicals.json" file regex in dispatcher refer doc