Content Rules#

A content rule will automatically perform an action when a certain event, known as a trigger, takes place.

Content rules can perform routine tasks, including the following.

  • Move content from one folder to another when that content item is published.

  • Send email when a content item is deleted.

  • Delete content after a certain date.

Note

These docs are generated by code tests, therefore you will see some test rules appear here.

Available content rules in a Plone site can be listed and queried by accessing the /@content-rules endpoint in any context. Access requires the ManageContentRules permission.

http

GET /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X GET http://nohost/plone/@content-rules -H "Accept: application/json" --user admin:secret

httpie

http http://nohost/plone/@content-rules Accept:application/json -a admin:secret

python-requests

requests.get('http://nohost/plone/@content-rules', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))
HTTP/1.1 200 OK
Content-Type: application/json

{
    "content-rules": {
        "acquired_rules": [],
        "assignable_rules": [],
        "assigned_rules": [
            {
                "bubbles": true,
                "description": "First rule added in the testing setup",
                "enabled": true,
                "global_enabled": true,
                "id": "rule-1",
                "title": "First test rule",
                "trigger": "Comment added",
                "url": "http://localhost:55001/plone/++rule++rule-1/@@manage-elements"
            },
            {
                "bubbles": true,
                "description": "Second rule added in the testing setup",
                "enabled": true,
                "global_enabled": true,
                "id": "rule-2",
                "title": "Second test rule",
                "trigger": "Comment added",
                "url": "http://localhost:55001/plone/++rule++rule-2/@@manage-elements"
            }
        ]
    }
}

The API consumer can assign, unassign, enable, disable, apply to subfolders, or disable apply to subfolders any of the rules available in the portal.

Verb

URL

Action

POST

/@content-rules/{rule-id}

Add rule to context

GET

/@content-rules/

Get acquired, assignable, and assigned rules

PATCH

/@content-rules/ with RAW Body

enable or disable,

apply to subfolders or disable apply to subfolders, move down or move up

DELETE

/@content-rules/ with RAW Body

Unassign rule on context

Assigning a new Content rule with POST#

To assign a content rule to a context, send a POST request to the <context>/@content-rules endpoint:

http

POST /plone/@content-rules/rule-1 HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X POST http://nohost/plone/@content-rules/rule-1 -H "Accept: application/json" --user admin:secret

httpie

http POST http://nohost/plone/@content-rules/rule-1 Accept:application/json -a admin:secret

python-requests

requests.post('http://nohost/plone/@content-rules/rule-1', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully assigned the rule rule-1"
}

Getting content rule for a context with GET#

To get content rules that are assigned, assignable, or acquired for a context, send a GET request to the <context>/@content-rules endpoint:

http

GET /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X GET http://nohost/plone/@content-rules -H "Accept: application/json" --user admin:secret

httpie

http http://nohost/plone/@content-rules Accept:application/json -a admin:secret

python-requests

requests.get('http://nohost/plone/@content-rules', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "content-rules": {
        "acquired_rules": [],
        "assignable_rules": [],
        "assigned_rules": [
            {
                "bubbles": true,
                "description": "First rule added in the testing setup",
                "enabled": true,
                "global_enabled": true,
                "id": "rule-1",
                "title": "First test rule",
                "trigger": "Comment added",
                "url": "http://localhost:55001/plone/++rule++rule-1/@@manage-elements"
            },
            {
                "bubbles": true,
                "description": "Second rule added in the testing setup",
                "enabled": true,
                "global_enabled": true,
                "id": "rule-2",
                "title": "Second test rule",
                "trigger": "Comment added",
                "url": "http://localhost:55001/plone/++rule++rule-2/@@manage-elements"
            }
        ]
    }
}

Changing content rules for a context with PATCH#

To make changes on content rule assignments for a context, send a PATCH request to the <context>/@content-rules endpoint:

Apply on subfolders#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "form.button.Bubble": true,
    "rule_ids": [
        "rule-1",
        "rule-2"
    ]
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Bubble": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret

httpie

echo '{
  "form.button.Bubble": true,
  "rule_ids": [
    "rule-1",
    "rule-2"
  ]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Bubble': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully applied ['rule-1', 'rule-2'] to subfolders"
}

Disable apply on subfolders#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "form.button.NoBubble": true,
    "rule_ids": [
        "rule-1",
        "rule-2"
    ]
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.NoBubble": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret

httpie

echo '{
  "form.button.NoBubble": true,
  "rule_ids": [
    "rule-1",
    "rule-2"
  ]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.NoBubble': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Disabled apply to subfolders for ['rule-1', 'rule-2']"
}

Enable#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "form.button.Enable": true,
    "rule_ids": [
        "rule-1",
        "rule-2"
    ]
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Enable": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret

httpie

echo '{
  "form.button.Enable": true,
  "rule_ids": [
    "rule-1",
    "rule-2"
  ]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Enable': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully enabled rules ['rule-1', 'rule-2']"
}

Disable#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "form.button.Disable": true,
    "rule_ids": [
        "rule-1",
        "rule-2"
    ]
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Disable": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret

httpie

echo '{
  "form.button.Disable": true,
  "rule_ids": [
    "rule-1",
    "rule-2"
  ]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Disable': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully disabled rules ['rule-1', 'rule-2']"
}

Move up#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "operation": "move_up",
    "rule_id": "rule-2"
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"operation": "move_up", "rule_id": "rule-2"}' --user admin:secret

httpie

echo '{
  "operation": "move_up",
  "rule_id": "rule-2"
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'operation': 'move_up', 'rule_id': 'rule-2'}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully applied the move_up"
}

Move down#

http

PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "operation": "move_down",
    "rule_id": "rule-1"
}

curl

curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"operation": "move_down", "rule_id": "rule-1"}' --user admin:secret

httpie

echo '{
  "operation": "move_down",
  "rule_id": "rule-1"
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'operation': 'move_down', 'rule_id': 'rule-1'}, auth=('admin', 'secret'))

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "message": "Successfully applied the move_down"
}

Unassign content rules with DELETE#

To unassign content rules on a context, send a DELETE request to the <context>/@content-rules endpoint:

http

DELETE /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "rule_ids": [
        "rule-1"
    ]
}

curl

curl -i -X DELETE http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"rule_ids": ["rule-1"]}' --user admin:secret

httpie

echo '{
  "rule_ids": [
    "rule-1"
  ]
}' | http DELETE http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.delete('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'rule_ids': ['rule-1']}, auth=('admin', 'secret'))

Response:

HTTP/1.1 204 No Content
Content-Type: text/html;charset=utf-8