What is the correct parameter list for contentLib.create()?

Enonic version: 6.0.0

In the docs for contentLib.create, the parameter list mentions the parameter “branch”. In the example below, this parameter is not used. Instead, the example lists “draft: true” as a possible parameter. Which is correct? Do they do the same thing?

Also, when I output the result after creating the content, there is no information about which branch the content was created in. This differs from the example in the docs, which specifies that the result should have a “draft”-element. Is this intended?

1 Like

You are right.
The example and result are not up-to-date. It should be written "branch: ‘draft’” instead of "draft: true”
About the result of the content creation: Yes there is no information about its branch inside of the content. It is intended

I will fix the documentation. Thank you for letting us know

Thanks for the answer. Next question:

When I create a content in branch: “master”, or omit the parameter and create the content in the “portal/master”-context, the content does not appear in the content list in the admin console.

If I create the content in branch: “draft”, or create the content in the “portal/draft”-context, it appears as expected.

It seems to me that a content needs to be in the draft branch to be listed in the admin console. Is this a bug in 6.0.X, or intended behaviour?

It is intentional, yes. What you see when working in admin is the draft branch. Thus, anything created in master branch (without going through draft branch first) will not be visible.

We are working on an “pull/update” feature that lets you update draft with changes from master (like a reverse publish).

I have leveraged this MASTER content functionality when using data that has been imported from external resources.
This way you separate content that can be edited and not.

The downside is that content in draft mode depending on content in MASTER can’t be previewed correctly.

Runar, if you do this consequently, you could change your api calls for the specific “master only items” to search for content in master branch spesifically.

1 Like

Thanks, Thomas! I even found this exact thing mentioned in the docs. Silly me for not reading the documentation thoroughly enough.

Is there an easy way for me to create the content in the draft branch, and publish it programatically with JavaScript? Or is this the pull/update feature you mention?


I created external content in draft and publish it. Can’t give you the exact code (customer) but what we did was.

  1. Created a Service that can Create, Read, Update and Delete a content in draft and returns the content ID. (http://xp.readthedocs.org/en/stable/reference/libraries/content/index.html)
  2. Used the admin interface: /admin/rest/content/publish to publish the content with the content ID.

I learned a lot by using dev tools in chrome to see whats going on behind the scenes.

happy coding :smile:

1 Like

Looks like we might be missing this in the api. Expect solution for 6.1+

Thanks a bunch for the tip, Runar! I did not know about those rest endpoints. Was pretty easy to do what you describe, and I now have similar functionality available in my project.

Cheers! :blush:

1 Like