> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # CreateRule # Package: feedbackModeration # Namespace: ModerationRules # Method link: https://dev.wix.com/docs/api-reference/crm/community/feedback-moderation/moderation-rules/create-rule.md ## Permission Scopes: Manage Moderation Rules: SCOPE.MODERATION.MANAGE-MODERATION-RULES ## Introduction Creates a rule. You can create up to 20 rules per namespace. --- ## REST API ### Schema ``` Method: createRule Description: Creates a rule. You can create up to 20 rules per namespace. URL: https://www.wixapis.com/moderation/v1/rules Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: rule, rule.namespace, rule.audience, rule.trigger, rule.action Method parameters: param name: rule | type: Rule | required: true - name: namespace | type: string | description: The app name and entity which the rule belongs to. Currently, moderation rules support [Comments](https://dev.wix.com/docs/rest/crm/community/comments/comments/introduction.md) and [Reviews](https://dev.wix.com/docs/rest/crm/community/reviews/reviews/introduction.md): + When the `namespace` is `comments` the format is `comments/{APP_ID}`. For example, for moderating content on Wix Blog the `namespace` is `"comments/14bcded7-0066-7c35-14d7-466cb3f09103"`. + When the `namespace` is `reviews` the format is `reviews/{APP_NAME}`. For example, for moderating content on Wix Reviews the `namespace` is `"reviews/stores"`. To retrieve the GUID for a Wix app, see [Apps Created By Wix](https://dev.wix.com/docs/rest/articles/get-started/apps-created-by-wix.md). | required: true - name: name | type: string | description: Rule name. - name: audience | type: Audience | description: Audience to which the rule applies. | required: true - ONE-OF: - name: newMembersOptions | type: NewMembersOptions | description: Options for new members. **Note:** This object is relevant only when `type` is `NEW_MEMBERS`. - name: durationInHours | type: integer | description: For how many hours the member is new. - name: type | type: Type | description: Audience type. - enum: VISITORS, MEMBERS, MEMBERS_AND_VISITORS, NEW_MEMBERS - name: trigger | type: Trigger | description: A condition that triggers the rule. **Note:** If you need to have several triggers for the same `namespace`, create separate rules. | required: true - ONE-OF: - name: patternsOptions | type: Patterns | description: Options for the patterns trigger. - name: words | type: array | description: List of words that can trigger a rule. The `*` wildcard can be used to match a partial word. For example: - `spam`: Matches only "spam". - `spam*`: Matches "spam", "spammer", "spammy". - `*spam`: Matches "antispam", "multispam". - `sp*m`: Matches "spim", "spam", "spum". - name: expressions | type: array | description: [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). - name: contentFeaturesOptions | type: ContentFeatures | description: Options for the content features trigger. - name: videos | type: boolean | description: Whether the content contains videos. - name: images | type: boolean | description: Whether the content contains images. - name: links | type: boolean | description: Whether the content contains links. - name: attachments | type: boolean | description: Whether the content contains attachments or files. - name: attributeOptions | type: Attribute | description: Options for the attributes trigger. You can only have 1 attribute per rule. - name: name | type: string | description: Attribute name. - name: values | type: array | description: Attribute values. - name: type | type: Type | description: Trigger type. - enum: - PATTERNS: The trigger is a specific word or phrase. You can specify additional options in the `patternsOptions` object. - CONTENT_FEATURES: The rule is triggered when non-textual features, such as videos, images, links, and attachments, exist in the content. You can specify additional options in the `contentFeaturesOptions` object. - ATTRIBUTE: A custom trigger based on an attribute and its value. For example, if you'd like to check all reviews with a low rating, then `name` would be `rating`, and `values` would be `[1, 2]`. You can specify additional options in the `patternsOptions` object. - ALWAYS: There is no specific trigger. The rule is triggered whenever new content is created or existing content is updated, with no other conditions required. - name: exemptions | type: Exemptions | description: List of site members or groups to whom the rule doesn't apply. - name: memberGroups | type: array | description: List of member groups. - name: memberIds | type: array | description: List of member GUIDs. - name: action | type: Action | description: What action should be taken after the rule is triggered. | required: true - name: type | type: Type | description: Action type. - enum: - UNKNOWN_TYPE: - REJECT: Reject the content without any further review. - NEEDS_MANUAL_APPROVAL: Send the content for manual review. - name: enabled | type: boolean | description: Whether the rule is enabled. - name: extendedFields | type: ExtendedFields | description: Custom field data for the rule object. **Note:** You must configure extended fields using schema plugin extensions in your app's dashboard before you can access the extended fields with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). Return type: CreateRuleResponse - name: rule | type: Rule | description: Created rule. - name: id | type: string | description: Rule GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the rule is updated. To prevent conflicting changes, the existing `revision` must be used when updating a rule. - name: createdDate | type: string | description: Date and time when the rule was created. - name: updatedDate | type: string | description: Date and time when the rule was updated. - name: namespace | type: string | description: The app name and entity which the rule belongs to. Currently, moderation rules support [Comments](https://dev.wix.com/docs/rest/crm/community/comments/comments/introduction.md) and [Reviews](https://dev.wix.com/docs/rest/crm/community/reviews/reviews/introduction.md): + When the `namespace` is `comments` the format is `comments/{APP_ID}`. For example, for moderating content on Wix Blog the `namespace` is `"comments/14bcded7-0066-7c35-14d7-466cb3f09103"`. + When the `namespace` is `reviews` the format is `reviews/{APP_NAME}`. For example, for moderating content on Wix Reviews the `namespace` is `"reviews/stores"`. To retrieve the GUID for a Wix app, see [Apps Created By Wix](https://dev.wix.com/docs/rest/articles/get-started/apps-created-by-wix.md). - name: name | type: string | description: Rule name. - name: audience | type: Audience | description: Audience to which the rule applies. - ONE-OF: - name: newMembersOptions | type: NewMembersOptions | description: Options for new members. **Note:** This object is relevant only when `type` is `NEW_MEMBERS`. - name: durationInHours | type: integer | description: For how many hours the member is new. - name: type | type: Type | description: Audience type. - enum: VISITORS, MEMBERS, MEMBERS_AND_VISITORS, NEW_MEMBERS - name: trigger | type: Trigger | description: A condition that triggers the rule. **Note:** If you need to have several triggers for the same `namespace`, create separate rules. - ONE-OF: - name: patternsOptions | type: Patterns | description: Options for the patterns trigger. - name: words | type: array | description: List of words that can trigger a rule. The `*` wildcard can be used to match a partial word. For example: - `spam`: Matches only "spam". - `spam*`: Matches "spam", "spammer", "spammy". - `*spam`: Matches "antispam", "multispam". - `sp*m`: Matches "spim", "spam", "spum". - name: expressions | type: array | description: [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). - name: contentFeaturesOptions | type: ContentFeatures | description: Options for the content features trigger. - name: videos | type: boolean | description: Whether the content contains videos. - name: images | type: boolean | description: Whether the content contains images. - name: links | type: boolean | description: Whether the content contains links. - name: attachments | type: boolean | description: Whether the content contains attachments or files. - name: attributeOptions | type: Attribute | description: Options for the attributes trigger. You can only have 1 attribute per rule. - name: name | type: string | description: Attribute name. - name: values | type: array | description: Attribute values. - name: type | type: Type | description: Trigger type. - enum: - PATTERNS: The trigger is a specific word or phrase. You can specify additional options in the `patternsOptions` object. - CONTENT_FEATURES: The rule is triggered when non-textual features, such as videos, images, links, and attachments, exist in the content. You can specify additional options in the `contentFeaturesOptions` object. - ATTRIBUTE: A custom trigger based on an attribute and its value. For example, if you'd like to check all reviews with a low rating, then `name` would be `rating`, and `values` would be `[1, 2]`. You can specify additional options in the `patternsOptions` object. - ALWAYS: There is no specific trigger. The rule is triggered whenever new content is created or existing content is updated, with no other conditions required. - name: exemptions | type: Exemptions | description: List of site members or groups to whom the rule doesn't apply. - name: memberGroups | type: array | description: List of member groups. - name: memberIds | type: array | description: List of member GUIDs. - name: action | type: Action | description: What action should be taken after the rule is triggered. - name: type | type: Type | description: Action type. - enum: - UNKNOWN_TYPE: - REJECT: Reject the content without any further review. - NEEDS_MANUAL_APPROVAL: Send the content for manual review. - name: enabled | type: boolean | description: Whether the rule is enabled. - name: extendedFields | type: ExtendedFields | description: Custom field data for the rule object. **Note:** You must configure extended fields using schema plugin extensions in your app's dashboard before you can access the extended fields with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: TOO_MANY_RULES | Description: Exceeded the limit of rules for this `namespace`. ``` ### Examples ### Create a rule to manually approve reviews with a low rating ```curl curl -X POST https://www.wixapis.com/moderation/v1/rules \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "rule": { "namespace": "reviews/stores", "name": "Check for Store Review Rating", "audience": { "type": "MEMBERS_AND_VISITORS" }, "trigger": { "attribute": { "values": ["1", "2"], "name": "rating" } }, "action": { "type": "NEEDS_MANUAL_APPROVAL" }, "enabled": true } }' ``` ### Create a rule to reject comments that contain the "win a free" phrase ```curl curl -X POST https://www.wixapis.com/moderation/v1/rules \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "rule": { "namespace": "comments/6b0414fa-c128-4df7-9968-7c4a5c45e49a", "name": "Check for Win a Free Phrase", "audience": { "type": "MEMBERS_AND_VISITORS" }, "trigger": { "patterns": { "words": ["win a free"] } }, "action": { "type": "REJECT" }, "enabled": true } }' ``` ### Create a rule to manually approve reviews that contain videos ```curl curl -X POST https://www.wixapis.com/moderation/v1/rules \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "rule": { "namespace": "reviews/stores", "name": "Check for Videos", "audience": { "type": "MEMBERS_AND_VISITORS" }, "trigger": { "contentFeatures": { "videos": true } }, "action": { "type": "NEEDS_MANUAL_APPROVAL" }, "enabled": true } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.feedbackModeration.ModerationRules.createRule(rule) Description: Creates a rule. You can create up to 20 rules per namespace. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: rule, rule.namespace, rule.audience, rule.trigger, rule.action Method parameters: param name: rule | type: Rule | required: true - name: namespace | type: string | description: The app name and entity which the rule belongs to. Currently, moderation rules support [Comments](https://dev.wix.com/docs/rest/crm/community/comments/comments/introduction.md) and [Reviews](https://dev.wix.com/docs/rest/crm/community/reviews/reviews/introduction.md): + When the `namespace` is `comments` the format is `comments/{APP_ID}`. For example, for moderating content on Wix Blog the `namespace` is `"comments/14bcded7-0066-7c35-14d7-466cb3f09103"`. + When the `namespace` is `reviews` the format is `reviews/{APP_NAME}`. For example, for moderating content on Wix Reviews the `namespace` is `"reviews/stores"`. To retrieve the GUID for a Wix app, see [Apps Created By Wix](https://dev.wix.com/docs/rest/articles/get-started/apps-created-by-wix.md). | required: true - name: name | type: string | description: Rule name. - name: audience | type: Audience | description: Audience to which the rule applies. | required: true - ONE-OF: - name: newMembersOptions | type: NewMembersOptions | description: Options for new members. **Note:** This object is relevant only when `type` is `NEW_MEMBERS`. - name: durationInHours | type: integer | description: For how many hours the member is new. - name: type | type: Type | description: Audience type. - enum: VISITORS, MEMBERS, MEMBERS_AND_VISITORS, NEW_MEMBERS - name: trigger | type: Trigger | description: A condition that triggers the rule. **Note:** If you need to have several triggers for the same `namespace`, create separate rules. | required: true - ONE-OF: - name: patternsOptions | type: Patterns | description: Options for the patterns trigger. - name: words | type: array | description: List of words that can trigger a rule. The `*` wildcard can be used to match a partial word. For example: - `spam`: Matches only "spam". - `spam*`: Matches "spam", "spammer", "spammy". - `*spam`: Matches "antispam", "multispam". - `sp*m`: Matches "spim", "spam", "spum". - name: expressions | type: array | description: [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). - name: contentFeaturesOptions | type: ContentFeatures | description: Options for the content features trigger. - name: videos | type: boolean | description: Whether the content contains videos. - name: images | type: boolean | description: Whether the content contains images. - name: links | type: boolean | description: Whether the content contains links. - name: attachments | type: boolean | description: Whether the content contains attachments or files. - name: attributeOptions | type: Attribute | description: Options for the attributes trigger. You can only have 1 attribute per rule. - name: name | type: string | description: Attribute name. - name: values | type: array | description: Attribute values. - name: type | type: Type | description: Trigger type. - enum: - PATTERNS: The trigger is a specific word or phrase. You can specify additional options in the `patternsOptions` object. - CONTENT_FEATURES: The rule is triggered when non-textual features, such as videos, images, links, and attachments, exist in the content. You can specify additional options in the `contentFeaturesOptions` object. - ATTRIBUTE: A custom trigger based on an attribute and its value. For example, if you'd like to check all reviews with a low rating, then `name` would be `rating`, and `values` would be `[1, 2]`. You can specify additional options in the `patternsOptions` object. - ALWAYS: There is no specific trigger. The rule is triggered whenever new content is created or existing content is updated, with no other conditions required. - name: exemptions | type: Exemptions | description: List of site members or groups to whom the rule doesn't apply. - name: memberGroups | type: array | description: List of member groups. - name: memberIds | type: array | description: List of member GUIDs. - name: action | type: Action | description: What action should be taken after the rule is triggered. | required: true - name: type | type: Type | description: Action type. - enum: - UNKNOWN_TYPE: - REJECT: Reject the content without any further review. - NEEDS_MANUAL_APPROVAL: Send the content for manual review. - name: enabled | type: boolean | description: Whether the rule is enabled. - name: extendedFields | type: ExtendedFields | description: Custom field data for the rule object. **Note:** You must configure extended fields using schema plugin extensions in your app's dashboard before you can access the extended fields with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). Return type: PROMISE - name: _id | type: string | description: Rule GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the rule is updated. To prevent conflicting changes, the existing `revision` must be used when updating a rule. - name: _createdDate | type: Date | description: Date and time when the rule was created. - name: _updatedDate | type: Date | description: Date and time when the rule was updated. - name: namespace | type: string | description: The app name and entity which the rule belongs to. Currently, moderation rules support [Comments](https://dev.wix.com/docs/rest/crm/community/comments/comments/introduction.md) and [Reviews](https://dev.wix.com/docs/rest/crm/community/reviews/reviews/introduction.md): + When the `namespace` is `comments` the format is `comments/{APP_ID}`. For example, for moderating content on Wix Blog the `namespace` is `"comments/14bcded7-0066-7c35-14d7-466cb3f09103"`. + When the `namespace` is `reviews` the format is `reviews/{APP_NAME}`. For example, for moderating content on Wix Reviews the `namespace` is `"reviews/stores"`. To retrieve the GUID for a Wix app, see [Apps Created By Wix](https://dev.wix.com/docs/rest/articles/get-started/apps-created-by-wix.md). - name: name | type: string | description: Rule name. - name: audience | type: Audience | description: Audience to which the rule applies. - ONE-OF: - name: newMembersOptions | type: NewMembersOptions | description: Options for new members. **Note:** This object is relevant only when `type` is `NEW_MEMBERS`. - name: durationInHours | type: integer | description: For how many hours the member is new. - name: type | type: Type | description: Audience type. - enum: VISITORS, MEMBERS, MEMBERS_AND_VISITORS, NEW_MEMBERS - name: trigger | type: Trigger | description: A condition that triggers the rule. **Note:** If you need to have several triggers for the same `namespace`, create separate rules. - ONE-OF: - name: patternsOptions | type: Patterns | description: Options for the patterns trigger. - name: words | type: array | description: List of words that can trigger a rule. The `*` wildcard can be used to match a partial word. For example: - `spam`: Matches only "spam". - `spam*`: Matches "spam", "spammer", "spammy". - `*spam`: Matches "antispam", "multispam". - `sp*m`: Matches "spim", "spam", "spum". - name: expressions | type: array | description: [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). - name: contentFeaturesOptions | type: ContentFeatures | description: Options for the content features trigger. - name: videos | type: boolean | description: Whether the content contains videos. - name: images | type: boolean | description: Whether the content contains images. - name: links | type: boolean | description: Whether the content contains links. - name: attachments | type: boolean | description: Whether the content contains attachments or files. - name: attributeOptions | type: Attribute | description: Options for the attributes trigger. You can only have 1 attribute per rule. - name: name | type: string | description: Attribute name. - name: values | type: array | description: Attribute values. - name: type | type: Type | description: Trigger type. - enum: - PATTERNS: The trigger is a specific word or phrase. You can specify additional options in the `patternsOptions` object. - CONTENT_FEATURES: The rule is triggered when non-textual features, such as videos, images, links, and attachments, exist in the content. You can specify additional options in the `contentFeaturesOptions` object. - ATTRIBUTE: A custom trigger based on an attribute and its value. For example, if you'd like to check all reviews with a low rating, then `name` would be `rating`, and `values` would be `[1, 2]`. You can specify additional options in the `patternsOptions` object. - ALWAYS: There is no specific trigger. The rule is triggered whenever new content is created or existing content is updated, with no other conditions required. - name: exemptions | type: Exemptions | description: List of site members or groups to whom the rule doesn't apply. - name: memberGroups | type: array | description: List of member groups. - name: memberIds | type: array | description: List of member GUIDs. - name: action | type: Action | description: What action should be taken after the rule is triggered. - name: type | type: Type | description: Action type. - enum: - UNKNOWN_TYPE: - REJECT: Reject the content without any further review. - NEEDS_MANUAL_APPROVAL: Send the content for manual review. - name: enabled | type: boolean | description: Whether the rule is enabled. - name: extendedFields | type: ExtendedFields | description: Custom field data for the rule object. **Note:** You must configure extended fields using schema plugin extensions in your app's dashboard before you can access the extended fields with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: TOO_MANY_RULES | Description: Exceeded the limit of rules for this `namespace`. ``` ### Examples ### createRule ```javascript import { moderationRules } from '@wix/moderation-rules'; async function createRule(rule) { const response = await moderationRules.createRule(rule); }; ``` ### createRule (with elevated permissions) ```javascript import { moderationRules } from '@wix/moderation-rules'; import { auth } from '@wix/essentials'; async function myCreateRuleMethod(rule) { const elevatedCreateRule = auth.elevate(moderationRules.createRule); const response = await elevatedCreateRule(rule); } ``` ### createRule (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { moderationRules } from '@wix/moderation-rules'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { moderationRules }, // Include the auth strategy and host as relevant }); async function createRule(rule) { const response = await myWixClient.moderationRules.createRule(rule); }; ``` ---