Expand my Community achievements bar.

SOLVED

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. 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 Accepted Solution

Avatar

Correct answer by
Level 4
1 Reply

Avatar

Correct answer by
Level 4

Hi @giterdun345,

 

If the error is related to CORS, the below article might help -

https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/understand-cros...

 

Regards,

Manpreet