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.

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

GET /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.getContentRules({
  token: login.data.token,
  path: '/events',
});

Example response:

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

{
  "content-rules": {
    "acquired_rules": [],
    "assignable_rules": [
      {
        "id": "rule-2",
        "title": "Content Rule 2",
        "description": "Description for Content Rule 2"
      }
    ],
    "assigned_rules": [
      {
        "id": "rule-1",
        "title": "Content Rule 1",
        "description": "Description for Content Rule 1",
        "bubbles": true,
        "enabled": false,
        "global_enabled": false,
        "trigger": "onAfterAdd"
      }
    ]
  }
}

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
DELETE /@content-rules/ with RAW Body Unassign rule on context

Assigning an new Content rule with POST

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

POST /events/@content-rules/rule-2 HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.createContentRule({
  token: login.data.token,
  path: '/events',
  data: { rule: 'rule-2' },
});

Example response:

HTTP/1.1 201 Created
Content-Type: application/json

{
  "message": "Successfully assigned the content rule rule-2"
}

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 subfolder

PATCH /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

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

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.updateContentRule({
  token: login.data.token,
  path: '/events',
  data: {
    'form.button.Bubble': true,
    rule_ids: ['rule-1'],
  },
});

Example response:

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

{
  "message": "Successfully enabled rules rule-1 to subfolders"
}

Disable apply on subfolder

PATCH /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

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

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.updateContentRule({
  token: login.data.token,
  path: '/events',
  data: {
    'form.button.NoBubble': true,
    rule_ids: ['rule-1'],
  },
});

Example response:

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

{
  "message": "Successfully disabled rules rule-1 to subfolders"
}

Enable

PATCH /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

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

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.updateContentRule({
  token: login.data.token,
  path: '/events',
  data: {
    'form.button.Enable': true,
    rule_ids: ['rule-1'],
  },
});

Example response:

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

{
  "message": "Successfully enabled rules rule-1"
}

Disable

PATCH /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

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

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.updateContentRule({
  token: login.data.token,
  path: '/events',
  data: {
    'form.button.Disable': true,
    rule_ids: ['rule-1'],
  },
});

Example response:

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

{
  "message": "Successfully disabled rules rule-1"
}

Unassign content rules with DELETE

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

DELETE /events/@content-rules HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

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

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });

const { data } = await cli.deleteContentRule({
  token: login.data.token,
  path: '/events',
  data: {
    rule_ids: ['rule-1'],
  },
});

Example response:

HTTP/1.1 204 No Content


This site uses Just the Docs, a documentation theme for Jekyll.