Expand my Community achievements bar.

SOLVED

sample JSON structure to create content fragment using Assets HTTP API

Avatar

Level 4

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? 
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

 

 

View solution in original post

4 Replies

Avatar

Level 4

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.

 

Avatar

Correct answer by
Community Advisor

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