Register custom content model using REST API

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
nenad982
Active Member

Register custom content model using REST API

Hello,

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).

We created a custom content model and we tried to use the:

POST api/cmm/upload

web script which was used by Model Manager feature in Admin Console from Share but we have a problem because we have <mandatory-aspects> tag in the model:

https://issues.alfresco.com/jira/browse/MNT-18953

Does anybody know how we can upload and register new custom content model using only remote API (CMIS API, REST)?

Thank you...

1 Reply
Moderator
Moderator

Re: Register custom content model using REST API

This is not ideally the use case always and it is preffered approach to deploy the models programatically via spring beans.

But there is a workaroud for your use case, You can upload your models to Data Dictionary/Models folder using upload (/api/upload) REST API. 

You need to find the nodeRef of the Models folder via search which will be used for uploading the file via upload api.

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):

GET: http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Data Dictionary/Models?cmisselector=object
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.
 
"alfcmis:nodeRef": {
            "id": "alfcmis:nodeRef",
            "localName": "nodeRef",
            "displayName": "Alfresco Node Ref",
            "queryName": "alfcmis:nodeRef",
            "type": "id",
            "cardinality": "single",
            "value": "workspace://SpacesStore/a9a9f477-5c57-11dc-ad6c-5136d620963c"
        }
Now you got the nodeRef of the Models folder, you can fire upload api to upload the file to Data Dictionary/Models folder.
 
POST127.0.0.1:8080/alfresco/service/api/upload 
 
RequiredParams: filedata and destination
 
Here filedata param holds the actual file and destination holds the nodeRef. 
 
Example: 
filedata : example-model.xml
destination : workspace://SpacesStore/a9a9f477-5c57-11dc-ad6c-5136d620963c
 
For more details on upload api see here: https://docs.alfresco.com/5.0/references/RESTful-UploadUploadPost.html (document links to version 5.0, but it works in all versions). 
 
Once model xml file is uploaded in Models folder, it will be inactive by default , You would need to activate it. 
 
 
Pass the POST request with following params:
 
Required params:
 
t= /admin/admin-repoconsole
repo-cmd = activate model example-model.xml 

 

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. Look at this doc if you need more details: https://docs.alfresco.com/6.1/concepts/csrf-policy.html

 

There may be better ways to achieve this use case, someone else can provide additonal options.