Expand my Community achievements bar.

SOLVED

Assets API: Unable to Create Content Fragment via post request.

Avatar

Level 5

I am trying to create content fragment using Assets API via POST request. Here's how my JSON looks like:

 

{
"class": [
"assets/asset"
],
"properties": {
"description": "Content Cateogry: Mutation-Example-02",
"title": "Mutation-Example-02",
"contentFragment": true,
"createdBy": "shivam_sahil@optum.com",
"elementsOrder": [
"title",
"uri"
],
"elements": {
"title": {
"variationsOrder": [],
"translatable": true,
":type": "string",
"variations": {},
"dataType": "string",
"title": "Title",
"multiValue": false,
"value": "Mutation Example"
},
"uri": {
"variationsOrder": [],
"translatable": true,
":type": "string",
"variations": {},
"dataType": "string",
"title": "URI",
"multiValue": false,
"value": "health-resources/mutation-example-02"
}
},
"name": "Mutation-Example-02"
}
}
 
Endpoint:
 
However this fails with 500 internal server error. Can someone tell me the right structure of JSON?
 
I am having content fragment model category as shown below:
title: string (Text Field)
uri: string (Text Field)
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @spidey1405,

In general, it looks some information are missing in your JSON, e.g. cq:model property which is mandatory. Please have a look under below documentation:

According to above, this is how correct JSON structure looks like for CF creation:

{
  "properties": {
    "cq:model": "/conf/path/to/model",
    "title": "string",
    "description": "string",
    "metadata": {
      "additionalProp1": "string",
      "additionalProp2": "string",
      "additionalProp3": "string"
    },
    "elements": {
      "{element1Name}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      },
      "{element2Name}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      },
      "{elementNName}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      }
    }
  }
}

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @spidey1405,

In general, it looks some information are missing in your JSON, e.g. cq:model property which is mandatory. Please have a look under below documentation:

According to above, this is how correct JSON structure looks like for CF creation:

{
  "properties": {
    "cq:model": "/conf/path/to/model",
    "title": "string",
    "description": "string",
    "metadata": {
      "additionalProp1": "string",
      "additionalProp2": "string",
      "additionalProp3": "string"
    },
    "elements": {
      "{element1Name}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      },
      "{element2Name}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      },
      "{elementNName}": {
        "value": "<p>The HTML content of the element.</p>",
        ":type": "text/html",
        "variations": {
          "{variation1Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{variation2Name}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          },
          "{elementNName}": {
            "value": "<p>The HTML content of the element.</p>",
            ":type": "text/html"
          }
        }
      }
    }
  }
}