how to fetch json file from DAM and use it in HTL file in JavaScript in AEM as a cloud service | Adobe Higher Education
Skip to main content
Level 4
March 15, 2023
Resuelto

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

  • March 15, 2023
  • 5 respuestas
  • 4544 visualizaciones

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 .
 
Este tema ha sido cerrado para respuestas.
Mejor respuesta de nitesh_kumar-1

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-configuration.html?lang=en#example-filter-section

 

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_filters.any 

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

 

5 respuestas

arunpatidar
Community Advisor
Community Advisor
March 15, 2023

Hi,

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

Arun Patidar
Level 4
March 15, 2023

Hi @arunpatidar 

Thank you for your response

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

arunpatidar
Community Advisor
Community Advisor
March 15, 2023
nitesh_kumar-1
Adobe Employee
Adobe Employee
March 15, 2023

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

 

Level 4
March 15, 2023

Hi, @nitesh_kumar-1 

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?

nitesh_kumar-1
Adobe Employee
Adobe Employee
March 15, 2023

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-configuration.html?lang=en#example-filter-section

 

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_filters.any 

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

 

Rohit_Utreja
Community Advisor
Community Advisor
March 15, 2023

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

Nirmal_Jose
Adobe Employee
Adobe Employee
March 15, 2023

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

Adobe Employee
March 15, 2023

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