Asset API (post request) for creation of content fragment is not working in AEM6.5 | Adobe Higher Education
Skip to main content
Nishanth_KR
Level 2
January 27, 2025
Beantwortet

Asset API (post request) for creation of content fragment is not working in AEM6.5

  • January 27, 2025
  • 1 Antwort
  • 917 Ansichten

I have a CF model linked to a CF folder under DAM. When I create a CF manually using the Touch UI, it works perfectly, and I can create and retrieve the CF successfully. However, when I try to create a CF using the Asset API, I receive a 500 error response. Upon checking the logs, I found the following error.

POST /api/assets/content-management/country-mapping/test.json HTTP/1.1] com.adobe.granite.rest.impl.servlet.PostRequest Exception during request processing.
java.lang.NullPointerException: null
at com.adobe.granite.rest.impl.servlet.JSONUtil.walk(JSONUtil.java:56) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.JSONUtil.walk(JSONUtil.java:64) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.JSONUtil.toJcrMap(JSONUtil.java:51) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.ModifyingRequest.createOrModifyResource(ModifyingRequest.java:102) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.PostRequest.doHandle(PostRequest.java:56) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.AbstractRequest.handle(AbstractRequest.java:75) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.DefaultServlet.handleRequest(DefaultServlet.java:101) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at com.adobe.granite.rest.impl.servlet.DefaultServlet.doPost(DefaultServlet.java:159) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:146) [org.apache.sling.api:2.22.0.B002]
at com.adobe.granite.rest.impl.servlet.DefaultServlet.mayService(DefaultServlet.java:275) [com.adobe.granite.rest.api:1.1.16.CQ650-B0007]
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:342) [org.apache.sling.api:2.22.0.B002]
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:374) [org.apache.sling.api:2.22.0.B002]
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:579) [org.apache.sling.engine:2.7.10.B0006]
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) [org.apache.sling.engine:2.7.10.B0006]
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82) [org.apache.sling.engine:2.7.10.B0006]
at com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter.doFilter(AssetContentDispositionFilter.java:96) [com.adobe.granite.rest.assets:1.0.58.CQ650-B0002]

Beste Antwort von anupampat

Hi @nishanth_kr ,

 

I was able to create a CF using below JSON

{ "properties": { "contentFragment": true, "name": "test", "cq:model": "/conf/global/settings/dam/cfm/models/product-data", "title": "test", "description": "test", "elementsOrder": [ "someData1", "someData2" ], "elements": { "someData1": "dfdf", "someData2": "abc" } } }

 But when I added some rubbish data on "elements" which are not part of the CF Model, it gives me a 500 Response.

Maybe there's a mismatch between the data or data type with the CF Model & the CF you are trying to create.

Ps- I tried it on AEM as a cloud.

 

Regards,

Anupam Patra

1 Antwort

anupampat
Community Advisor
Community Advisor
January 27, 2025

Hi @nishanth_kr ,

 

Can you confirm you are using these APIs correctly to create the CF ?

https://developer.adobe.com/experience-manager/reference-materials/6-5/assets-api-content-fragments/index.html#/

 

Regards,

Anupam Patra

Nishanth_KR
Level 2
January 27, 2025

@anupampatYes, I am using the API format specified in the Swagger documentation. Here is the JSON data for the request and body that I am trying to post to create the CF.

Request URL : 

http://localhost:4502/api/assets/content-management/country-mapping/test.json


Request body:

{ "properties": { "contentFragment": true, "name": "test", "cq:model": "/conf/my-content-fragments/settings/dam/cfm/models/country-number-mapping", "title": "test", "description": "test", "createdBy": "admin", "created": 1737115187690, "modifiedBy": "admin", "modified": 1737115187690, "elementsOrder": [ "country", "phoneNumber" ], "elements": { "country": { "variationsOrder": [], ":type": "string", "variations": {}, "dataType": "string", "title": "country", "multiValue": false, "value": "India" }, "phoneNumber": { "variationsOrder": [], ":type": "string", "variations": {}, "dataType": "string", "title": "Phone Number", "multiValue": false, "value": "1111111111" } } } }

 

anupampat
Community Advisor
anupampatCommunity AdvisorAntwort
Community Advisor
January 27, 2025

Hi @nishanth_kr ,

 

I was able to create a CF using below JSON

{ "properties": { "contentFragment": true, "name": "test", "cq:model": "/conf/global/settings/dam/cfm/models/product-data", "title": "test", "description": "test", "elementsOrder": [ "someData1", "someData2" ], "elements": { "someData1": "dfdf", "someData2": "abc" } } }

 But when I added some rubbish data on "elements" which are not part of the CF Model, it gives me a 500 Response.

Maybe there's a mismatch between the data or data type with the CF Model & the CF you are trying to create.

Ps- I tried it on AEM as a cloud.

 

Regards,

Anupam Patra