Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

I am calling http://localhost:4502/api/assets.json in React app and getting 204- No Content Response

Avatar

Level 2

Hello, 

I am trying to use an asset in the react app located in the ui.frontend of my project and to conduct some test to see if the api would work I called:

 

const myHeaders = new Headers();
    myHeaders.append("Authorization"`Basic YWRtaW46YWRtaW4=`);
    myHeaders.append("Content-Type""application/json");

     fetch(
      {
        method: "GET",
        headers: myHeaders,
        redirect: "follow",
      }
    )
      .then((response=> console.log(response))
      .catch((error=> console.log(error));
 
and I receive a response {type: 'cors', url: 'http://localhost:4502/api/assets/myAssetsFolder.json', redirected: false, status: 204, ok: true, …
I am able to call this endpoint in the browser, in curl and in Postman but cannot get any response in the react application. I have exhausted a search through the documentation and cannot find any information. I have allowed the HTTP Methods in CORS configuration also. Can some one confirm that I can call this API in a react application in AEM and why do I always get a response 204- No Content?
1 Reply

Avatar

Employee Advisor

Could you please refer this : https://wanago.io/2018/11/05/cors-cross-origin-resource-sharing/ and section: Access-Control-Allow-Origin header.