Create custom aspect and that assign property using Rest API

cancel
Showing results for 
Search instead for 
Did you mean: 
ssaimon
Member II

Create custom aspect and that assign property using Rest API

Hi, I am a new user of Alfresco. I need to understand if it is possible to create a custom aspect and assign propertis as specified here: Create Customer Aspect but using rest API or CURL command? 

I will be using the aspect to create rules on folders. That also has to be done using the rest API or Command-line as we have to turn off the shared service. Thanks

 

1 Reply
abhinavmishra14
Advanced

Re: Create custom aspect and that assign property using Rest API

As far as i know, there are no API endpoints which lets you use model manager. 

Reference to all V1 Apis can be found here: https://api-explorer.alfresco.com/api-explorer/#/

Even there are no repository apis that can help using the model manager. 

If your goal is to create aspects and models for the purpose of handling rules/behaviors, i would recommend bootstrapping it. 

If your requirement is that you create aspects and properties very frequently you can also use dynamic model deployment approach : 

https://docs.alfresco.com/5.2/tasks/deploy-dynamic.html

https://docs.alfresco.com/5.2/concepts/content-model-deploy.html

And manage them via admin console: https://docs.alfresco.com/5.2/tasks/adminconsole-modelconsole.html

Note that, you can make only incremental changes to the model.

For you specific use case, you can upload the model XML file to /Data Dictionary/Models folder using V1 Upload Rest API or Respository FileUpload API and then enable it via Is Active flag (cm:modelActive) of the content model via share ui or use admin console to activate/deploy the model.

 

Here are some list of api calls which can help you achieve what you are looking for:

1- Get the node id of /Data Dictionary/Models folder using below API call:

GET Model Folder Id : 

curl -X GET "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?relativePath=Data%20Dictionary&skipCount=0&maxItems=100&alf_ticket=TICKET_f5cff7c76f7a87139f24dc0c6540dd1b57479552"

From the response grab the "id" which is the nodeRef id of Models folder. 

e.g.:

{
                "entry": {
                    "createdAt": "2020-10-28T19:33:22.851+0000",
                    "isFolder": true,
                    "isFile": false,
                    "createdByUser": {
                        "id": "System",
                        "displayName": "System"
                    },
                    "modifiedAt": "2020-10-28T20:53:26.872+0000",
                    "modifiedByUser": {
                        "id": "admin",
                        "displayName": "Administrator"
                    },
                    "name": "Models",
                    "id": "a9a9f477-5c57-11dc-ad6c-5136d620963c",
                    "nodeType": "cm:folder",
                    "parentId": "4de64712-954c-44b6-b439-890c1550bcc1"
                }
            }

2- Use the upload api to upload the model file into Data Dictionary/Models folder:

Upload model xml to Data Dictionary/Models:

curl -X POST -F filedata=@pub-model.xml http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/a9a9f477-5c57-11dc-ad6c-5136d620963c/children?alf_ticket=TICKET_f5cff7c76f7a87139f24dc0c6540dd1b57479552

3- Activate the model, grab the node id of the model xml from the upload response (see highligted in the url below):

Update cm:modelActive property 

curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"properties": { "cm:modelActive":true}}' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/1a8345f6-1b66-48b1-a581-1319f3d6bfbd?alf_ticket=TICKET_f5cff7c76f7a87139f24dc0c6540dd1b57479552'

 

You can also try uploading the model xml with cm:modelActive property using below api call if it works for you:

curl -X POST -F filedata=@pub-model.xml -F "cm:modelActive=true" http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/a9a9f477-5c57-11dc-ad6c-5136d620963c/children?alf_ticket=TICKET_f5cff7c76f7a87139f24dc0c6540dd1b57479552

 

 

 

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)