<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Register custom content model using REST API in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84666#M25779</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;we are working with Alfresco v6.1 and we have to register a new custom content model using only remote access to the repository (no access to Repository/Data Dictionary/Models in Share, no access to Model Manager in Share or registration using Spring bean is possible).&lt;/P&gt;&lt;P&gt;We created a custom content model and we tried to use the:&lt;/P&gt;&lt;P&gt;POST&amp;nbsp;api/cmm/upload&lt;/P&gt;&lt;P&gt;web script which was used by Model Manager feature in Admin Console from Share but we have a problem because we have &amp;lt;mandatory-aspects&amp;gt; tag in the model:&lt;/P&gt;&lt;P&gt;&lt;A href="https://issues.alfresco.com/jira/browse/MNT-18953" target="_blank" rel="noopener nofollow noreferrer"&gt;https://issues.alfresco.com/jira/browse/MNT-18953&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Does anybody know how we can upload and register new custom content model using only remote API (CMIS API, REST)?&lt;/P&gt;&lt;P&gt;Thank you...&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2019 14:44:39 GMT</pubDate>
    <dc:creator>nenad982</dc:creator>
    <dc:date>2019-12-03T14:44:39Z</dc:date>
    <item>
      <title>Register custom content model using REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84666#M25779</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;we are working with Alfresco v6.1 and we have to register a new custom content model using only remote access to the repository (no access to Repository/Data Dictionary/Models in Share, no access to Model Manager in Share or registration using Spring bean is possible).&lt;/P&gt;&lt;P&gt;We created a custom content model and we tried to use the:&lt;/P&gt;&lt;P&gt;POST&amp;nbsp;api/cmm/upload&lt;/P&gt;&lt;P&gt;web script which was used by Model Manager feature in Admin Console from Share but we have a problem because we have &amp;lt;mandatory-aspects&amp;gt; tag in the model:&lt;/P&gt;&lt;P&gt;&lt;A href="https://issues.alfresco.com/jira/browse/MNT-18953" target="_blank" rel="noopener nofollow noreferrer"&gt;https://issues.alfresco.com/jira/browse/MNT-18953&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Does anybody know how we can upload and register new custom content model using only remote API (CMIS API, REST)?&lt;/P&gt;&lt;P&gt;Thank you...&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 14:44:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84666#M25779</guid>
      <dc:creator>nenad982</dc:creator>
      <dc:date>2019-12-03T14:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Register custom content model using REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84667#M25780</link>
      <description>&lt;P&gt;This is not ideally the use case always and it is preffered approach to deploy the models programatically via spring beans.&lt;/P&gt;
&lt;P&gt;But there is a workaroud for your use case, You can upload your models to&amp;nbsp;&lt;SPAN&gt;Data Dictionary/Models folder using upload (/api/upload) REST API.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You need to find the nodeRef of the Models folder via search which will be used for uploading the file via upload api.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Here is an example to get the nodeRef of Models folder using an ootb approach (However its up to you to choose how to get the nodeRef):&lt;/U&gt;&lt;/P&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="3mqnl-0-0"&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;
&lt;PRE&gt;&lt;STRONG&gt;GET:&lt;/STRONG&gt; http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/&lt;STRONG&gt;Data Dictionary/Models?cmisselector=object&lt;/STRONG&gt;&lt;/PRE&gt;
This will return a json response containing the metadata of Models folder which will have the nodeRef. You can parse the json and get the nodeRef from there. Here is the snippet of metadata you would be parsing.&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;
&lt;PRE&gt;&lt;STRONG&gt;"alfcmis:nodeRef": {
&lt;/STRONG&gt;            "id": "alfcmis:nodeRef",
            "localName": "nodeRef",
            "displayName": "Alfresco Node Ref",
            "queryName": "alfcmis:nodeRef",
            "type": "id",
            "cardinality": "single",
            &lt;STRONG&gt;"value": "workspace://SpacesStore/a9a9f477-5c57-11dc-ad6c-5136d620963c"&lt;/STRONG&gt;
        }&lt;/PRE&gt;
Now you got the nodeRef of the Models folder, you can fire upload api to upload the file to Data Dictionary/Models folder.&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;STRONG&gt;POST&lt;/STRONG&gt;:&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;127.0.0.1:8080/alfresco/service/api/upload&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;STRONG&gt;&lt;EM&gt;RequiredParams:&amp;nbsp;filedata and&amp;nbsp;destination&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;SPAN&gt;Here filedata param holds the actual file and destination holds the nodeRef.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;U&gt;Example:&amp;nbsp;&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;SPAN&gt;filedata : example-model.xml&lt;BR /&gt;destination : workspace://SpacesStore/a9a9f477-5c57-11dc-ad6c-5136d620963c&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;SPAN&gt;For more details on upload api see here:&amp;nbsp;&lt;A href="https://docs.alfresco.com/5.0/references/RESTful-UploadUploadPost.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/5.0/references/RESTful-UploadUploadPost.html&lt;/A&gt;&amp;nbsp;(document links to version 5.0, but it works in all versions).&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&lt;SPAN&gt;Once model xml file is uploaded in Models folder, it will be &lt;EM&gt;&lt;STRONG&gt;inactive&amp;nbsp;by default &lt;/STRONG&gt;&lt;/EM&gt;, You would need to &lt;EM&gt;&lt;STRONG&gt;activate&lt;/STRONG&gt; &lt;/EM&gt;it.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr" data-offset-key="3mqnl-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;To Activate the model, you can use&amp;nbsp;&lt;A href="http://127.0.0.1:8080/alfresco/s/admin/admin-repoconsole" target="_blank" rel="noopener nofollow noreferrer"&gt;http://127.0.0.1:8080/alfresco/s/admin/admin-repoconsole&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;Pass the POST request with following params:&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&lt;STRONG&gt;POST:&amp;nbsp;&lt;A href="http://127.0.0.1:8080/alfresco/s/admin/admin-repoconsole" target="_blank" rel="noopener nofollow noreferrer"&gt;http://127.0.0.1:8080/alfresco/s/admin/admin-repoconsole&lt;/A&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&lt;STRONG&gt;Required params:&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&lt;STRONG&gt;&lt;EM&gt;t=&amp;nbsp;/admin/admin-repoconsole&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="" data-block="true" data-editor="2bd60" data-offset-key="6vfvc-0-0"&gt;&lt;STRONG&gt;&lt;EM&gt;repo-cmd =&amp;nbsp;activate model example-model.xml&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;

&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Note, for this request you would need to pass the CSRF token param also in the request or disable the CSRF validation for this request path. &lt;/STRONG&gt;&lt;/EM&gt;Look at this doc if you need more details:&amp;nbsp;&lt;A href="https://docs.alfresco.com/6.1/concepts/csrf-policy.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.alfresco.com/6.1/concepts/csrf-policy.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;There may be better ways to achieve this use case, someone else can provide additonal options.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 21:42:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84667#M25780</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2019-12-03T21:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Register custom content model using REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84668#M25781</link>
      <description>&lt;P&gt;I achieved importing a custom content model through CMIS.&lt;BR /&gt;I used Javascript (NodeJs) code and the cmis npm package: &lt;A href="https://www.npmjs.com/package/cmis" target="_blank" rel="noopener nofollow noreferrer"&gt;https://www.npmjs.com/package/cmis&lt;/A&gt;&lt;BR /&gt;Alfresco does not support (did not implement) the createType method.&lt;BR /&gt;But you can create an "cm:dictionaryModel" with xml content in folder /Data Dictionary/Models to create a custom model (CMIS document type).&lt;BR /&gt;By setting the&amp;nbsp;'cm:modelActive' to true, the model is set active.&lt;/P&gt;&lt;P&gt;This is the code I use:&lt;/P&gt;&lt;PRE&gt;const cmis = require('cmis');
const fs = require('fs');

// Establish a connection with Alfresco and load the repository information
this.afSession = new cmis.CmisSession(afConfig.url);
this.afSession.setCredentials(afConfig.username, afConfig.password);
await this.afSession.loadRepositories();
// Find content model on file system and import into Alfresco
const contentModelNameWithExt = `${contentModelName}.xml`;
const filename = `./data/content-model/${contentModelNameWithExt}`;
const contentModelData = Buffer.from(fs.readFileSync(filename));
try {
  const modelsFolder = await this.afSession.getObjectByPath(`/Data Dictionary/Models`);
  const modelsFolderId = modelsFolder.succinctProperties['cmis:objectId'];
  const queryResponse = await this.afSession.query(
	`SELECT cmis:versionSeriesId FROM cm:dictionaryModel WHERE cmis:name='${contentModelNameWithExt}' AND IN_FOLDER('${modelsFolderId}')`
  );
  if (queryResponse &amp;amp;&amp;amp; queryResponse.results.length === 1) {
	console.log(`Updating in Alfresco: ${contentModelNameWithExt}`);
	const modelId = queryResponse.results[0].succinctProperties['cmis:versionSeriesId'];
	await this.afSession.setContentStream(modelId, contentModelData, true, contentModelNameWithExt);
	await this.afSession.updateProperties(modelId, { 'cm:modelActive': true });
  } else {
	console.log(`Creating in Alfresco: ${contentModelNameWithExt}`);
	await this.afSession.createDocument(modelsFolderId, contentModelData, {
	  'cmis:name': contentModelNameWithExt,
	  'cmis:objectTypeId': 'D:cm:dictionaryModel',
	  'cm:modelActive': true,
	});
  }
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 09:39:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/register-custom-content-model-using-rest-api/m-p/84668#M25781</guid>
      <dc:creator>stefanwalbers</dc:creator>
      <dc:date>2020-05-01T09:39:38Z</dc:date>
    </item>
  </channel>
</rss>

