Add Schedule Entries by Playlist

Adds a playlist's assets and ad breaks as entries within a live channel's schedule.

By default, a new schedule entry cannot conflict with an existing one. Use the conflict_resolution property to resolve scheduling conflicts.

Request

Request syntax:

POST /channels/Live Channel ID/schedule-playlist

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
Live Channel ID RequiredIdentifies a live channel by its system-defined ID.

Request body:

Define a schedule entry through the following properties:

NameData TypeDescription
conflict_resolutionStringDetermines how scheduling conflicts are handled. Valid values are: replace: Overwrite previously scheduled entries with the new entry being scheduled. Overwriting a schedule entry that is currently being streamed truncates it at the point-in-time defined by the new schedule entry's start time. trim-start: Trim the beginning of the asset to fit within the current scheduling gap. * trim-end: Trim from the end of the asset to fit within the current scheduling gap. Prevent previously scheduled entries from being overwritten by excluding this property from the request. Omitting this property causes our service to respond with a 409 Conflict when a scheduling conflict arises. Trimming an asset can affect the number of ads served. Specifically, we will not serve ads for an ad break positioned within a portion of the asset that is trimmed.
overwrite DeprecatedStringDetermines how scheduling conflicts are handled. The conflict_resolution property takes precedence over this deprecated property.
playlist_id RequiredStringIdentifies a playlist by its system-defined ID. Use the Get All Virtual Linear Playlists endpoint to retrieve a list of virtual linear playlists and their system-defined IDs.
start RequiredStringIndicates the start time (UTC) for the starting point at which schedule entries will be inserted. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ Key information: You must set this property to a point-in-time in the future. You cannot schedule a playlist so that it starts in the past. You may only set this start time to an available time slot. Our service returns a 400 Bad Request when attempting to set a start time during a time slot that is already taken by a previously scheduled entry. This occurs regardless of the conflict_resolution property. * Missing content slate occurs when there is a gap between scheduled entries. Set the start time to the previous entry's end time to prevent missing content slate.

Response

The response for a successful request contains the following properties:

NameData TypeDescription
@idStringIndicates the relative path to the requested endpoint.
@typeStringReturns Collection.
itemsList of dictionariesContains a list of the schedule entries that were created.
total_itemsIntegerIndicates the total number of recently created schedule entries.

items List

The items list describes each schedule entry through the following properties:

NameData TypeDescription
@idStringIndicates the relative path to an endpoint that returns this schedule entry.
@typeStringReturns Schedule.
ad_breaksList of integersIndicates the duration for each ad break associated with the asset.
content_idStringcontent_type: asset Identifies an asset by its system-defined ID.
content_typeStringIndicates whether the schedule entry points to an asset, ad break, or Live Slicer, or previously scheduled content. Valid values are: adassetslicerreplay_source
createdStringIndicates the timestamp (UTC) at which the schedule entry was created. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
descStringIndicates the schedule entry's description. If the schedule entry does not have a description, then this property's value varies by the type of schedule entry. Asset: Indicates the name assigned to the asset. Ad Break: Returns Ad Break. Schedule entries created through the CMS are not assigned a description.
durIntegerIndicates the schedule entry's duration in milliseconds.
endStringIndicates the schedule entry's end time (UTC). Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
external_idStringIndicates a schedule entry's custom ID.
idStringIdentifies a schedule entry by its system-defined ID.
lastmodStringIndicates the timestamp (UTC) at which the schedule entry was last modified. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
offsetIntegerIndicates playback offset in milliseconds. Playback offset occurs when an asset or ad break is scheduled to start in the past. Example: An offset value of 60000 is reported when an asset is scheduled for a minute in the past. For example, scheduling an asset for 11:00 AM when the current time is 11:01 AM generates an offset value of 60000.
ownerStringIndicates the system-defined ID for the user that owns the live channel associated with this schedule entry.
replaced_byStringIndicates the system-defined ID for the schedule entry that overwrote the current schedule entry.
replay_sourceStringcontent_type only Specifies the time frame of the content that should be played. Required values for replay_source as content_type: content_id, content_type, desc, dur, replay_source_start, replay_source_end.
replay_source_endStringcontent_type: replay_source only Specifies the time (UTC) the content should stop playing. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
replay_source_startStringcontent_type: replay_source only Specifies the time (UTC) the content should begin playing. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
sourceDictionaryIdentifies the playlist from which this schedule entry was created.
startStringIndicates the schedule entry's start time (UTC). Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ

source Dictionary

The source dictionary identifies the playlist from which this schedule entry was created.

NameData TypeDescription
idStringIndicates the system-defined ID for the playlist from which this schedule entry was created.
typeStringReturns playlist.

Sample Request/Response

Call the add_schedule_entries_by_playlist module (Python 3) to create schedule entries from the assets and ad breaks associated with a playlist. This module imports names from the api_auth module.

import json, requests, datetime, time
from api_auth import APICredentials, APIParams
channel_id = 'Hak3zjnPLSW5o0j8GMpzRMsa' # Replace with the ID for the desired live channel.
playlist_id = 'gh35hs89274748j2ab459ne7ud4f6cl3' # Replace with the ID for the desired playlist.

def convert_ts(utc_tstamp):
    """
        Convert a UTC timestamp to ISO 8601 format (YYYY-MM-DDThh:mm:ss.sZ).
        :param utc_tstamp: The UTC timestamp to convert (expected milliseconds)
    """
    iso_format = "%Y-%m-%dT%H:%M:%S.%fZ"
    try:
        _ts = float("{0:.3f}".format(utc_tstamp/1000.0))
        return "{}{}".format(datetime.datetime.utcfromtimestamp(_ts).strftime(iso_format)[:-4], "Z")
    except Exception:
        print ("Invalid timestamp: {}".format(utc_tstamp))
        raise

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

    def run(self):
        """
        Create mulitple schedule entries.
        """
        self._create_schedule_entries_by_playlist()

    def _create_schedule_entries_by_playlist(self):
        url = "{}{}{}{}".format(self.host, "/api/v4/channels/", channel_id, "/schedule-playlist")

        start = int((time.time() + 3600) * 1000.0) # 1 hour from now
        start = convert_ts(start)

        payload = {
            'playlist_id': playlist_id,
            'start': start
        }

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

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

        print(response.json())

ScheduleEntries().run()

Response:

{
	'@id': '/channels/Hak3zjnPLSW5o0j8GMpzRMsa/schedules?start=now&end=now+240m',
	'@type': 'TimeSeries',
	'start': '2022-12-19T19:48:24.000Z',
	'end': '2022-12-19T23:48:24.000Z',
	'items': [{
			'@id': '/channels/Hak3zjnPLSW5o0j8GMpzRMsa/schedules/631c7c0accbb4bc999ea5536aa81ce91',
			'@type': 'Schedule',
			'id': '631c7c0accbb4bc999ea5536aa81ce91',
			'content_id': '5574ff5e41c04bdd9ed5ed485c6a3211',
			'content_type': 'asset',
			'deleted': '',
			'desc': 'marketing-conference-2022-green-room-morning',
			'dur': 227968,
			'end': '2022-12-19T20:35:30.474Z',
			'external_id': '',
			'owner': '1234567890abcdefghijklmnopqrstu',
			'source': {
				'id': '18495b21df6c410a968f89da32a025ff',
				'type': 'playlist'
			},
			'start': '2022-12-19T20:31:42.506Z',
			'ad_breaks': [],
			'lastmod': '2022-12-19T19:31:43.065Z',
			'created': '2022-12-19T19:31:43.065Z'
		}, {
			'@id': '/channels/Hak3zjnPLSW5o0j8GMpzRMsa/schedules/05a882f291434e788fe09b413a83e8b4',
			'@type': 'Schedule',
			'id': '05a882f291434e788fe09b413a83e8b4',
			'content_id': 'fb19109d3cf6470a806e85307c70842e',
			'content_type': 'asset',
			'deleted': '',
			'desc': 'marketing-conference-2022-red-room-morning',
			'dur': 9856,
			'end': '2022-12-19T20:44:01.217Z',
			'external_id': '',
			'owner': '1234567890abcdefghijklmnopqrstu',
			'source': {
				'id': '18495b21df6c410a968f89da32a025ff',
				'type': 'playlist'
			},
			'start': '2022-12-19T20:43:51.361Z',
			'ad_breaks': [],
			'lastmod': '2022-12-19T19:43:51.709Z',
			'created': '2022-12-19T19:43:51.709Z'
		}, {
			'@id': '/channels/Hak3zjnPLSW5o0j8GMpzRMsa/schedules/2be08e891c544312a984361614b7ae35',
			'@type': 'Schedule',
			'id': '2be08e891c544312a984361614b7ae35',
			'content_id': 'a404b63430a7437a99995d3285a48be6',
			'content_type': 'asset',
			'deleted': '',
			'desc': 'marketing-conference-2022-blue-room-morning',
			'dur': 24493,
			'end': '2022-12-19T20:44:25.710Z',
			'external_id': '',
			'owner': '1234567890abcdefghijklmnopqrstu',
			'source': {
				'id': '18495b21df6c410a968f89da32a025ff',
				'type': 'playlist'
			},
			'start': '2022-12-19T20:44:01.217Z',
			'ad_breaks': [],
			'lastmod': '2022-12-19T19:43:51.709Z',
			'created': '2022-12-19T19:43:51.709Z'
		}
	]
}