2sxc 13 introduces a plethora of functionality to make reading and writing data easier from other systems.
- New JS API .data and .query
- New REST features to set Published state of data
- New REST features to set Metadata targets on create
- New REST features to set relationships on create
Here's an example of code requesting data in the new API:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
The new APIs have the following commands
sxc.data("ContentTypeName") will get you a object to work with data of this type. All the commands return standard promises. You can read more about it in the docs. These are the commands on that object:
delete(id) and delete(guid)
sxc.query("QueryName") will get you an object to work with this query. All the commands return standard promises. You can read more about it in the docs. These are the commands on that object:
getAll(urlParams) - other signatures also available
getStream(streamName) - other signatures also available
getStreams(streamNames) - other signatures also available
This should help you create awesome JS based applications using 2sxc data.
👉 also check out the tutorials
REST now controls Publishing and Draft
IsPublished to determine if something should be published or not. Allowed values are:
null or not set - just leave as is / default
true - set to published
false - set to not-published
"draft" - set the change to draft, leave the previous published version published
This is also documented in more details in the docs.
REST can can Add-To-Parent
When creating a new item you can also set a property
ParentRelationship. It must be an object with these fields:
Then upon creation it will add a reference to this new item to the parent, in that field on the specified index. Your more about it in the docs.
REST can create Metadata
When creating an item, you can say that it it metadata, and assign it to a target which it will be describing. This uses the For property. You can read more about it in the docs.
Have fun pimping your JS Apps!
Love from Switzerland,