Expand my Community achievements bar.

SOLVED

How to resolve 500 server error when creating a folder in AEM Headless via react frontend after configuring CORS and CSRF?

Avatar

Level 2

I'm working on a headless Adobe Experience Manager (AEM) project with React as the frontend. Just added some CORS and CSRF configurations to handle some other errors I have been encountering. Now getting an error when attempting to create a new folder under /content/dam/my-project/tests via a POST request. Using Assets API to create a folder in a specified location. It leads to an error 500 with AEM logging an AssetException indicating failure to create an asset at the specified path. Here's the error snippet in the error.log:

 

13.02.2024 12:51:16.523 *WARN* [[0:0:0:0:0:0:0:1] [1707828676513] POST /api/assets/my-project/tests/ HTTP/1.1] com.adobe.granite.rest.impl.servlet.PostRequest Exception during request processing.

com.adobe.granite.asset.api.AssetException: Failed to create Asset at path [/content/dam/my-project/tests]

at com.adobe.granite.asset.core.impl.AssetManagerImpl.createAsset(AssetManagerImpl.java:78) [com.adobe.granite.asset.core:2.2.76]

at com.adobe.granite.rest.assets.impl.DefaultAssetPlugin.createAsset(DefaultAssetPlugin.java:98) [com.adobe.granite.rest.assets:1.0.74]

at com.adobe.granite.rest.assets.impl.AssetResourceProvider.create(AssetResourceProvider.java:226) [com.adobe.granite.rest.assets:1.0.74]

 

Any ideas? Or additional tips to troubleshoot? Currently not much in the error logs apart from a 'failure to create asset' error.

Thanks. 

 

 

 

mvotos_0-1707830051958.png

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Solved: needed to include 'body: JSON.stringify({'

View solution in original post

3 Replies

Avatar

Community Advisor

Did you check the permission of the service user?

 

 

Pleas make sure that the user or service account making the API request has the necessary permissions to create node/folder/assets in the specified location. You can check this in the user administration section of AEM.

 

 

Is the tests/ node already exist? - Verify that the path /content/dam/my-project/tests

 

Check the server logs for any additional error messages that might give more information about what's causing the issue. Like caused by

 

Avatar

Community Advisor

@mvotos can you check the user which you are using to create folder in asset location does have permissions to create folder ? 

 

window.btoa(`${AEM_USERNAME}:${AEM_PASSWORD}`)

 

I tried the same in my local using admin user and its working for me  

Avatar

Correct answer by
Level 2

Solved: needed to include 'body: JSON.stringify({'