Update Rule

Updates a specific rule.

Request

Request syntax:

PATCH /rules/Rule ID

Define the following variable when submitting the above request:

VariableA variable represents a value that must be replaced. A variable consists of either a URL segment (e.g., "0001" in /0001/) or a query string value (e.g., "3" in mediaTypes=3).Description
Rule ID RequiredIdentifies a rule by its system-defined or external ID. Use the Get Multiple Rules endpoint to retrieve a list of rules and their IDs.

Request body parameters:

Pass the following request body parameters:

NameData TypeDescription
all_viewersBooleanDetermines whether this rule applies to all audiences. Default value: False
alternate_content_idStringIdentifies 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_loopBooleanDetermines whether alternate content will be looped. Valid values are: TrueFalse
alternate_content_typeStringDefines the type of alternate content that will be streamed to blacked out viewers. Valid case-sensitive values are: assetchannelslateslicer 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.
audienceStringall_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.
descStringDefines the name of the rule.
external_idStringDefines the external ID associated with this rule.

Response

A successful request returns a 200 OK response that contains the following properties:

NameData TypeDescription
@idStringIndicates the relative path to an endpoint that returns this rule.
@typeStringReturns Rule.
all_viewersBooleanIndicates whether this rule applies to all audiences. Default value: False
alternate_content_idStringIndicates 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_loopBooleanIndicates whether alternate content will be looped. Valid values are: TrueFalse
alternate_content_typeStringIndicates the type of alternate content that will be streamed to blacked out viewers. Valid case-sensitive values are: assetchannelslateslicer 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.
audienceStringall_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.
createdStringIndicates the timestamp (UTC) at which the rule was created. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
descStringIndicates the name of the rule.
external_idStringIndicates the external ID associated with this rule.
idStringIdentifies this rule by its system-defined ID.
ownerStringIndicates the system-defined ID for the user that owns this rule.

Sample Request/Response

Call the update_rule module (Python 3) to update a rule. This module imports names from the api_auth module.

import json, requests
from api_auth import APICredentials, APIParams
rule_id = 'c2eb5a555b9d45b7a43552f65a268075' # Replace with the ID for the desired rule.

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

    def run(self):
        """
        Update a rule.
        """
        self._update_rule()

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

        payload = {
            'alternate_content_type': 'asset', # Sets the type of alternate content.
            'alternate_content_id': '062048d702734ca6a38f3e7f8e4f4488' # Replace with the desired asset ID.
        }

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

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

        print(response.json())

Rule().run()

Response:

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