sample JSON structure to create content fragment using Assets HTTP API | Community
Skip to main content
thatsmeadarsh
Level 3
November 3, 2023
Solved

sample JSON structure to create content fragment using Assets HTTP API

  • November 3, 2023
  • 1 reply
  • 2320 views

I am trying to create a content fragment with some pre-filled values of content fragment model datatype using Assets API. I am unsure on the format of JSON I need to place in the Body. As per the doc its stating to include the JSON format but it is not working for me. 

Creation of CF is happening with the below JSON

{
"properties": {
"cq:model": "/conf/xxxx/xxx/xxx-headless-portal/settings/dam/cfm/models/sample-model",
"title": "Sample Model",
"description": "Sample model"
}
}
 
But I want to put more properties under the node 'jcr:content/data/master' . How should I structure the JSON? 
 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mahedi_Sabuj

Hi @thatsmeadarsh,

You're almost there, need to remove the curly braces `{}` around the element name, changing it from {jsonVal} to jsonVal.

{ "properties": { "cq:model": "/conf/.../settings/dam/cfm/models/sample-model", "title": "Sample Model", "description": "Sample model", "elements": { "jsonVal": { "value": "{}", ":type": "json" } } } }

 

 

1 reply

Mahedi_Sabuj
Community Advisor
Community Advisor
November 6, 2023
thatsmeadarsh
Level 3
November 7, 2023

Thanks for your response @mahedi_sabuj but unfortunately it seems like I am still missing something. Following the document I created the JSON structure in this way.

 

 

 

{ "properties": { "cq:model": "/conf/xx/xx/xx/settings/dam/cfm/models/sample-model", "title": "Sample Model", "description": "Sample model", "elements": { "{jsonVal}": { "value": "{}", ":type": "json" } } } }

 

My CF model contains only a single Data Type 'Json Object' . The property name of that is 'jsonVal' . After POST operation I get below error "status.message":"Could not update content element","status.code":500}} . It would be helpful if I get the ideal JSON format for this example. Thanks again for your response.

 

Mahedi_Sabuj
Community Advisor
Mahedi_SabujCommunity AdvisorAccepted solution
Community Advisor
November 7, 2023

Hi @thatsmeadarsh,

You're almost there, need to remove the curly braces `{}` around the element name, changing it from {jsonVal} to jsonVal.

{ "properties": { "cq:model": "/conf/.../settings/dam/cfm/models/sample-model", "title": "Sample Model", "description": "Sample model", "elements": { "jsonVal": { "value": "{}", ":type": "json" } } } }

 

 

Mahedi Sabuj