

# Creating and deleting using a batch command
<a name="about-batch-update-schedule"></a>

To create and delete actions in the schedule for a channel, you use the batch update schedule command. This command lets you perform multiple actions in one request. There isn't one command for creating actions and another for deleting actions.

**Important**  
When working with a started and running channel, use the **batch-update-schedule** command to add or remove actions. Use the **delete-schedule** command only on idle channels. The **delete-schedule** command will delete all scheduled actions and could cause service interruptions if used on a live channel. 

You can use the command as follows:
+ Submit a *single* request such as a request to do the following:
  + Create one action.
  + Delete one action.
+ Submit a *batch* request such as one request to do the following:
  + Create several actions.
  + Delete several actions.
  + Create one or more actions and delete one or more actions.

**Important**  
In a command that combines create actions and delete actions, the delete actions are *always* performed before the create actions. This means that MediaLive removes the delete actions from the schedule before it adds the create actions to the schedule.

**Topics**
+ [

# How a batch request works
](how-batch-schedule-requests-work.md)
+ [

# Batch command in different interfaces
](batchupdatecommand-interfaces.md)
+ [

# JSON payload in different interfaces
](batchupdatecommand-payloads.md)

# How a batch request works
<a name="how-batch-schedule-requests-work"></a>

The intention of batching is to pass or fail all the actions together. Therefore, AWS Elemental MediaLive validates batch actions together. MediaLive performs the following validation:
+ It ensures that each action that is created or deleted has an explicit or implied start time that is at least 15 seconds in the future. 
+ If an action refers to an existing action in the schedule, it ensures that the reference to the existing action is correct. For example, a follow input switch includes a reference to the action that it follows. That action must exist.

If the validation fails for any one action, it fails for all the actions in the batch.

If you don't want the actions to pass or fail together, don't submit a batch. Instead, create each action in its own batch update schedule command.

If the validation succeeds, MediaLive processes all the delete requests before the create requests, regardless of the start times of the actions.

**Example 1**  
An important use of batching is to perform several actions that must pass or fail together. For example, suppose that you want to remove the corporate logo and immediately insert a splice\$1insert (in order to go to an ad avail). To do that, you must create an action to remove the logo and another action to insert the splice\$1insert. However, you don't want MediaLive to insert the remove action if the splice\$1insert action fails, or vice versa. It's better if both actions fail because that allows you to fix the badly formed action, and then submit both actions again.

You therefore submit the two actions together, in one batch update schedule command. 

**Example 2**  
Another important use of batching is to fix an error in an action in the schedule. For example, you might want to fix an image overlay that hasn't started yet and that was created with the wrong start time. To do that, you submit one batch update schedule command with JSON that contains the following:
+ A payload to remove the original action to activate the image overlay. This action has the incorrect start time.
+ A payload to add a new action to activate the same image overlay. This action has the correct start time.

# Batch command in different interfaces
<a name="batchupdatecommand-interfaces"></a>

The batch update schedule command is represented differently in different interfaces: 
+ In the AWS CLI, the command is `batch-update-schedule`.
+ In the API, the command is represented by an `HTTP PUT` on `channels/channelId/schedule`.
+ In the AWS SDKs, the command is represented by constructs that are suitable to that SDK language.

# JSON payload in different interfaces
<a name="batchupdatecommand-payloads"></a>

The JSON payload for the command is different for the different interfaces:
+ In the AWS CLI, the contents of the payload depend on how you use the command:
  + You can enter a command with two parameters: `channel-id` and `--cli-input-json`. In this case, you create a file that repeats the channel ID and includes the JSON payload. 
  + You can enter a command with three parameters: one for the channel ID, one for the JSON payload for the create actions (if applicable), and one for the JSON payload for the delete actions (if applicable). You pass the payloads in the command. If both parameters are present, each parameter takes a separate payload. But the two payloads are validated and performed as a batch. 

  The payload for the AWS CLI is always pascal case (upper camel case). 
+ In the API, there is one payload with two sections, a `CREATES` section and a `DELETES` section. A request can contain one or both sections. 

  The payload for the API is always camel case for variable names and pascal case for classes.
+ In the AWS SDKs, the JSON payload is represented by constructs that are suitable to that SDK language. 

To get more familiar with individual actions, we recommend that you use the MediaLive console to create an action. After you create the action, use the [DescribeSchedule](viewing-schedule-using-cli.md) command in the appropriate interface (for example, the AWS CLI or an SDK) to obtain the raw JSON payload for the entire schedule. You can then copy individual actions and save them as models to use when working programmatically.