Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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]

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

6 Replies

Avatar

Level 7

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/...

 

Regards,

Anupam Patra

Avatar

Level 2

@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"
            }
        }
  }
}

 

Avatar

Correct answer by
Level 7

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

Avatar

Level 2

@anupampat

I am using AEM 6.5.20. Thanks for your help! I tried removing some data inside the elements JSON, but the POST request still didn’t work. However, I managed to solve the issue by following these steps:

  1. First, I made a POST request to create the CF without any metadata, which successfully created the CF.
  2. Then, I made a PUT request to update the metadata, which worked in my case.

I received a successful response after following the steps mentioned above.

    "properties": {
        "path": "/api/assets/content-management/country-mapping/test",
        "parentLocation": "/api/assets/content-management/country-mapping.json",
        "referer": "",
        "changes": [
            {
                "argument": "/api/assets/content-management/country-mapping/test",
                "type": "modified"
            }
        ],
        "location": "/api/assets/content-management/country-mapping/test.json",
        "status.message": "OK",
        "title": "Content modified /api/assets/content-management/country-mapping/test",
        "status.code": 200
    }

Avatar

Level 7

Hi @Nishanth_KR 

 

Encode the data in the JSON if any special characters are available 

 

Hope this helps

Avatar

Level 2

@PRATHYUSHA_VP  Thanks for your response. I found the solution based on @anupampat ’s reply and implemented a workaround. It’s working fine now. I am able to create a CFs via Asset API