---
updatedAt: 2025-10-09T17:40:40.000Z
agentTools:
  projectIndex: https://docs.uplynk.com/llms.txt
---

# Add Rule

v4

Adds a rule.

### Request

Request syntax:

POST /rules

Request body parameters:

Pass the following request body parameters:

| Name                     | Data Type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |         |       |                                                                                                                                                                                                                                                                                      |
| :----------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------ | :---- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| all\_viewers             | Boolean   | Determines whether this rule applies to all audiences.  Default value: False                                                                                                                                                                                                                                                                                                                                                                                                    |         |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_id   | String    | Identifies the alternate content that will be streamed to blacked out viewers by its ID. The alternate*content\_type parameter determines how you should configure this parameter.* alternate*content\_type: asset  Asset ID* alternate*content\_type: channel  Live Channel ID* alternate*content\_type: slicer  Live Slicer ID* alternate\_content\_type: slate  Conditional blackout slate will be streamed to blacked out viewers. This parameter should be an empty value. |         |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_loop | Boolean   | Determines whether alternate content will be looped. Valid values are: True                                                                                                                                                                                                                                                                                                                                                                                                     | False   |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_type | String    | Defines the type of alternate content that will be streamed to blacked out viewers. Valid case-sensitive values are: asset                                                                                                                                                                                                                                                                                                                                                      | channel | slate | slicer Identify alternate content through both the alternate\_content\_id and the alternate\_content\_type parameters. For example, specify a CMS asset by setting the alternate\_content\_type parameter to asset and the alternate\_content\_id parameter to the desired asset ID. |
| audience                 | String    | all\_viewers: false  Identifies an audience or superaudience by its system-defined ID.  This rule will only be applied to the specified audience when the all\_viewers parameter is set to False.                                                                                                                                                                                                                                                                               |         |       |                                                                                                                                                                                                                                                                                      |
| desc  Required           | String    | Defines the name of the rule.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |         |       |                                                                                                                                                                                                                                                                                      |
| external\_id             | String    | Defines the external ID associated with this rule.                                                                                                                                                                                                                                                                                                                                                                                                                              |         |       |                                                                                                                                                                                                                                                                                      |

### Response

A successful request returns a 201 Created response that contains the following properties:

| Name                     | Data Type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |         |       |                                                                                                                                                                                                                                                                                      |
| :----------------------- | :-------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :---- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| @id                      | String    | Indicates the relative path to an endpoint that returns this rule.                                                                                                                                                                                                                                                                                                                                                                                                                  |         |       |                                                                                                                                                                                                                                                                                      |
| @type                    | String    | Returns Rule.                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |         |       |                                                                                                                                                                                                                                                                                      |
| all\_viewers             | Boolean   | Indicates whether this rule applies to all audiences.  Default value: False                                                                                                                                                                                                                                                                                                                                                                                                         |         |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_id   | String    | Indicates the alternate content that will be streamed to blacked out viewers by its ID. The alternate*content\_type parameter determines the type of ID defined within this parameter.* alternate*content\_type: asset  Asset ID* alternate*content\_type: channel  Live Channel ID* alternate*content\_type: slicer  Live Slicer ID* alternate\_content\_type: slate  Conditional blackout slate will be streamed to blacked out viewers. This parameter should be an empty value. |         |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_loop | Boolean   | Indicates whether alternate content will be looped. Valid values are: True                                                                                                                                                                                                                                                                                                                                                                                                          | False   |       |                                                                                                                                                                                                                                                                                      |
| alternate\_content\_type | String    | Indicates the type of alternate content that will be streamed to blacked out viewers. Valid case-sensitive values are: asset                                                                                                                                                                                                                                                                                                                                                        | channel | slate | slicer Identify alternate content through both the alternate\_content\_id and the alternate\_content\_type parameters. For example, specify a CMS asset by setting the alternate\_content\_type parameter to asset and the alternate\_content\_id parameter to the desired asset ID. |
| audience                 | String    | all\_viewers: false  Indicates an audience or superaudience by its system-defined ID.  This rule will only be applied to the specified audience when the all\_viewers parameter is set to False.                                                                                                                                                                                                                                                                                    |         |       |                                                                                                                                                                                                                                                                                      |
| created                  | String    | Indicates the timestamp (UTC) at which the rule was created.  Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ                                                                                                                                                                                                                                                                                                                                                                           |         |       |                                                                                                                                                                                                                                                                                      |
| desc                     | String    | Indicates the name of the rule.                                                                                                                                                                                                                                                                                                                                                                                                                                                     |         |       |                                                                                                                                                                                                                                                                                      |
| external\_id             | String    | Indicates the external ID associated with this rule.                                                                                                                                                                                                                                                                                                                                                                                                                                |         |       |                                                                                                                                                                                                                                                                                      |
| id                       | String    | Identifies this rule by its system-defined ID.                                                                                                                                                                                                                                                                                                                                                                                                                                      |         |       |                                                                                                                                                                                                                                                                                      |
| owner                    | String    | Indicates the system-defined ID for the user that owns this rule.                                                                                                                                                                                                                                                                                                                                                                                                                   |         |       |                                                                                                                                                                                                                                                                                      |

### Sample Request/Response

The code below (Python 3) shows how to create a rule.

This code imports names from the `api_auth` module for V4 APIs (see below).

<TutorialTile
  backgroundColor="#018FF4"
  emoji="🦉"
  id="682d18228dd6230012097fad"
  link="https://docs.uplynk.com/v2.0/recipes/api-auth-for-classic-authentication-v4-apis"
  slug="api-auth-for-classic-authentication-v4-apis"
  title="API Auth for Classic Authentication (V4 APIs)"
/> 

```python
import json, requests
from api_auth import APICredentials, APIParams

class Rule:
    def __init__(self):
        self.host = "https://services.uplynk.com"

    def run(self):
        """
        Create a rule.
        """
        self._create_rule()

    def _create_rule(self):
        url = "{}{}".format(self.host, "/api/v4/rules")

        payload = {
            'desc': 'My New Rule', # Replace with the rule's name.
            'alternate_content_type': 'slate', # Sets alternate content to slate.
            'all_viewers': True # Applies this rule to all viewers.
        }

        headers = {'Content-Type': 'application/json'}

        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers
        )

        print(response.json())

Rule().run()
```

Response:

```json
{
	'@id': '/api/v4/rules/c1fb5a555b9d45b7a43552f65a268075',
	'@type': 'Rule',
	'created': '2021-07-01T23:34:38.215Z',
	'id': 'c1fb5a555b9d45b7a43552f65a268075',
	'owner': 'abc123def456ghi789jkl012mno345pq',
	'external_id': '',
	'audience': '',
	'alternate_content_type': 'slate',
	'alternate_content_id': '',
	'alternate_content_loop': True,
	'all_viewers': True,
	'desc': 'My New Rule'
}
```