What is the expected structure for an item of type "Rich Text" or "CMS" when I'm posting a collection item via the API?

I want to post collection items via the sitejet api and I would like to post items of type Rich Text or CMS. I have tried mirroring the response received as a result of a get request to the collection items, and I’ve tried posting raw HTML in the column. Both times, I got the error:

{"errors":[[{"name":"columns","message":"This value is not valid."}]]}

What is the structure of the body expected by your service?

1 Like

@Vaibhav_Joshi Could you post the payload that you tried to submit to the Collections API as well as the fields (screenshot) of the targeted collection?

For posting items to the Collections API make sure:

  • As column names you have to use the “Key” that is displayed in the Fields setup
    image
  • Do not post any columns that don’t exist as a field
  • Double-check the collection ID you’re posting into
  • For the formatting of richtext or CMS fields, refer to the example payload that you can see when you GET items through the API

For quick testing without actual coding you can also directly run API calls through the documentation at https://api.sitejet.io/api/doc (just add your Token through the Authorize button).

3 Likes

Thank you for the response, but I was able to figure this out after a good amount of trial and error. There has to be some documentation about these structures.

3 Likes

@Vaibhav_Joshi I would appreciate if you shared what was wrong with your payload so others (including us) can learn from it.

3 Likes

Yes, any insight is welcome for future reference

I have a description field which expects a CMS type in the API call. I created an item manually, fetched it via the get API and replicated the structure. The structure is an array of HTML elements in the JSON format below:

// POST request with stringified body containing:
{
items: [
  {
    columns: {
      'custom-columns': 'custom-values',
      description: [
        {
          type: 'text', // this field needs to be enumerated by the SJ team, as it can contain text/spacer/heading, etc.
          content: '<span>Actual HTML content to display</span>',
          css_class: 'if any',
          css_style: 'if any'
        }, // ... more elements with the same structure
      ]
    }
  }
]
}
1 Like