Skip to content

create_time_off

create_time_off(
    instance_id: InstanceIdOrArn,
    user_id: UserIdOrArn,
    shift_activity_id: ShiftActivityIdOrArn,
    start_at: datetime,
    end_at: datetime,
    approval_type: ApprovalType,
    *,
    config_overrides: Optional[ConnectSchedulingClientConfig] = None,
    description: Optional[Description] = None,
    rule_failure_action: Optional[RuleFailureAction] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateTimeOffResponse

Creates a time off request for a user. You don't provide a status, because Connect Customer owns the request lifecycle. To get the decided status, call GetTimeOff or use the time off state-change events.

ApprovalType controls who approves the request. You can specify one of the following values:

  • AWAIT_APPROVAL: the request waits in AWAITING_APPROVAL until you call ApproveTimeOff or RejectTimeOff. Rule evaluation and the overlap check run at approval, not at creation. A waiting request doesn't reserve its window, so another request for the same window can be approved first.

  • AUTOMATIC: Connect Customer evaluates the rules (time off balances and group allowances) and decides the request. The request can be PENDING while Connect Customer decides, and then ends APPROVED or REJECTED. If it overlaps another time off request for the user, the requested time off ends REJECTED with CONFLICTING_TIME_OFF_REQUEST. It also ends REJECTED if it overlaps overtime or voluntary time off. If the whole window is in the past, Connect Customer records failed rules as WARNING and doesn't reject the request, whatever the RuleFailureAction.

The staffing group's Supervisor approval needed setting doesn't apply to this operation. ApprovalType alone decides whether the request waits for approval. The operation fails with ValidationException on UserId in the following cases:

  • The user isn't in a staffing group, or the staffing group isn't associated with a forecast group.

  • Time off isn't enabled for the user's staffing group, or the user's staff rules don't allow time off.

To change the dates of a request, cancel it with CancelTimeOff and create a new request. The new request has a new TimeOffId.

Connect Customer doesn't check whether the principal that calls this operation supervises the user. The staffing group's approval settings also don't apply. IAM permissions are the only control. If you allow a principal to call this operation, that principal can send ApprovalType AUTOMATIC with RuleFailureAction OVERRIDE and approve a request past failed rules. Grant permission for this operation only to principals that you trust to override time off rules.

For information about time off in the Connect Customer admin website, see Time off management in the Connect Customer Administrator Guide.

Parameters:

  • instance_id (InstanceIdOrArn) –

    The identifier of the Connect Customer instance. This can be the ID or the ARN of the instance. You can find the instance ID in the Amazon Resource Name (ARN) of the instance.

  • user_id (UserIdOrArn) –

    The identifier of the user who the time off request is for. This can be the ID or the ARN of the user.

  • shift_activity_id (ShiftActivityIdOrArn) –

    The identifier of the shift activity that defines the type of time off being requested. This can be the ID or the ARN of the shift activity. It must be a time off activity. Activities that aren't set as Requestable are accepted.

  • start_at (datetime) –

    The start of the time off window, inclusive. It must be no earlier than one year before the current date. Connect Customer stores the value as sent, to the millisecond.

  • end_at (datetime) –

    The end of the time off window, exclusive. It must be after StartAt and no later than 24 months after the current date. Connect Customer stores the value as sent, to the millisecond.

  • description (Optional[Description], default: None ) –

    A description recorded on the time off request. If you omit it, the request has no description.

  • approval_type (ApprovalType) –

    Controls who approves the request. AWAIT_APPROVAL waits for an ApproveTimeOff or RejectTimeOff call. AUTOMATIC has Connect Customer decide the request. For details, see CreateTimeOff.

  • rule_failure_action (Optional[RuleFailureAction], default: None ) –

    Controls what happens when a configured rule fails. REJECT, the default, records an ERROR and ends the request REJECTED, unless the whole window is in the past. OVERRIDE records a WARNING and ends the request APPROVED, like the Override time off rules option in the Connect Customer admin website. OVERRIDE requires AUTOMATIC. With AWAIT_APPROVAL, OVERRIDE fails with ValidationException. Set it on ApproveTimeOff instead. OVERRIDE never waives CONFLICTING_TIME_OFF_REQUEST.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request, Connect Customer returns the result of that request and doesn't create another time off request. If you don't provide a token, the AWS SDK populates this field. If you reuse a client token with a different request body, the request fails with ValidationException. For more information about idempotency, see Making retries safe with idempotent APIs.

Raises:

Examples:

To create a time off request that waits for approval The following example creates a time off request for one day. The request is created in AWAITING_APPROVAL until an ApproveTimeOff or RejectTimeOff call decides it.

>>> client.create_time_off(instance_id='12345678-1234-1234-1234-123456789012', user_id='87654321-4321-4321-4321-210987654321', shift_activity_id='11112222-3333-4444-5555-666677778888', start_at=1795424400, end_at=1795453200, description='Family event', approval_type='AWAIT_APPROVAL')
Source code in docs_src/capo_connectscheduling/_services/connect_scheduling.py
def create_time_off(
    self,
    instance_id: "capo_connectscheduling.types.instance_id_or_arn.InstanceIdOrArn",
    user_id: "capo_connectscheduling.types.user_id_or_arn.UserIdOrArn",
    shift_activity_id: "capo_connectscheduling.types.shift_activity_id_or_arn.ShiftActivityIdOrArn",
    start_at: datetime.datetime,
    end_at: datetime.datetime,
    approval_type: "capo_connectscheduling.types.approval_type.ApprovalType",
    *,
    config_overrides: Optional[ConnectSchedulingClientConfig] = None,
    description: Optional[
        "capo_connectscheduling.types.description.Description"
    ] = None,
    rule_failure_action: Optional[
        "capo_connectscheduling.types.rule_failure_action.RuleFailureAction"
    ] = None,
    client_token: Optional[
        "capo_connectscheduling.types.client_token.ClientToken"
    ] = None,
) -> "capo_connectscheduling.types.create_time_off_response.CreateTimeOffResponse":
    """<p>Creates a time off request for a user. You don't provide a status, because Connect Customer owns the request lifecycle. To get the decided status, call <code>GetTimeOff</code> or use the time off state-change events.</p> <p> <code>ApprovalType</code> controls who approves the request. You can specify one of the following values:</p> <ul> <li> <p> <code>AWAIT_APPROVAL</code>: the request waits in <code>AWAITING_APPROVAL</code> until you call <code>ApproveTimeOff</code> or <code>RejectTimeOff</code>. Rule evaluation and the overlap check run at approval, not at creation. A waiting request doesn't reserve its window, so another request for the same window can be approved first.</p> </li> <li> <p> <code>AUTOMATIC</code>: Connect Customer evaluates the rules (time off balances and group allowances) and decides the request. The request can be <code>PENDING</code> while Connect Customer decides, and then ends <code>APPROVED</code> or <code>REJECTED</code>. If it overlaps another time off request for the user, the requested time off ends <code>REJECTED</code> with <code>CONFLICTING_TIME_OFF_REQUEST</code>. It also ends <code>REJECTED</code> if it overlaps overtime or voluntary time off. If the whole window is in the past, Connect Customer records failed rules as <code>WARNING</code> and doesn't reject the request, whatever the <code>RuleFailureAction</code>.</p> </li> </ul> <p>The staffing group's <i>Supervisor approval needed</i> setting doesn't apply to this operation. <code>ApprovalType</code> alone decides whether the request waits for approval. The operation fails with <code>ValidationException</code> on <code>UserId</code> in the following cases:</p> <ul> <li> <p>The user isn't in a staffing group, or the staffing group isn't associated with a forecast group.</p> </li> <li> <p>Time off isn't <a href="https://docs.aws.amazon.com/connect/latest/adminguide/enable-to.html">enabled</a> for the user's staffing group, or the user's staff rules don't allow time off.</p> </li> </ul> <p>To change the dates of a request, cancel it with <code>CancelTimeOff</code> and create a new request. The new request has a new <code>TimeOffId</code>.</p> <note> <p>Connect Customer doesn't check whether the principal that calls this operation supervises the user. The staffing group's approval settings also don't apply. IAM permissions are the only control. If you allow a principal to call this operation, that principal can send <code>ApprovalType</code> <code>AUTOMATIC</code> with <code>RuleFailureAction</code> <code>OVERRIDE</code> and approve a request past failed rules. Grant permission for this operation only to principals that you trust to override time off rules.</p> </note> <p>For information about time off in the Connect Customer admin website, see <a href="https://docs.aws.amazon.com/connect/latest/adminguide/scheduling-time-off.html">Time off management</a> in the <i>Connect Customer Administrator Guide</i>.</p>

    Args:
        instance_id: <p>The identifier of the Connect Customer instance. This can be the ID or the ARN of the instance. You can <a href="https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html">find the instance ID</a> in the Amazon Resource Name (ARN) of the instance.</p>
        user_id: <p>The identifier of the user who the time off request is for. This can be the ID or the ARN of the user.</p>
        shift_activity_id: <p>The identifier of the shift activity that defines the type of time off being requested. This can be the ID or the ARN of the shift activity. It must be a time off activity. Activities that aren't set as <i>Requestable</i> are accepted.</p>
        start_at: <p>The start of the time off window, inclusive. It must be no earlier than one year before the current date. Connect Customer stores the value as sent, to the millisecond.</p>
        end_at: <p>The end of the time off window, exclusive. It must be after <code>StartAt</code> and no later than 24 months after the current date. Connect Customer stores the value as sent, to the millisecond.</p>
        description: <p>A description recorded on the time off request. If you omit it, the request has no description.</p>
        approval_type: <p>Controls who approves the request. <code>AWAIT_APPROVAL</code> waits for an <code>ApproveTimeOff</code> or <code>RejectTimeOff</code> call. <code>AUTOMATIC</code> has Connect Customer decide the request. For details, see <code>CreateTimeOff</code>.</p>
        rule_failure_action: <p>Controls what happens when a configured rule fails. <code>REJECT</code>, the default, records an <code>ERROR</code> and ends the request <code>REJECTED</code>, unless the whole window is in the past. <code>OVERRIDE</code> records a <code>WARNING</code> and ends the request <code>APPROVED</code>, like the <i>Override time off rules</i> option in the Connect Customer admin website. <code>OVERRIDE</code> requires <code>AUTOMATIC</code>. With <code>AWAIT_APPROVAL</code>, <code>OVERRIDE</code> fails with <code>ValidationException</code>. Set it on <code>ApproveTimeOff</code> instead. <code>OVERRIDE</code> never waives <code>CONFLICTING_TIME_OFF_REQUEST</code>.</p>
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request, Connect Customer returns the result of that request and doesn't create another time off request. If you don't provide a token, the AWS SDK populates this field. If you reuse a client token with a different request body, the request fails with <code>ValidationException</code>. For more information about idempotency, see <a href="https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/">Making retries safe with idempotent APIs</a>.</p>

    Raises:
        capo_connectscheduling.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient permissions to perform this action.</p>
        capo_connectscheduling.errors.conflict_exception.ConflictException: <p>The request could not be processed because of a conflict with the current state of the resource.</p>
        capo_connectscheduling.errors.internal_server_exception.InternalServerException: <p>The request processing failed because of an error or failure with the service.</p>
        capo_connectscheduling.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found.</p>
        capo_connectscheduling.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would cause a service quota to be exceeded.</p>
        capo_connectscheduling.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling.</p>
        capo_connectscheduling.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by an AWS service.</p>
        capo_connectscheduling.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a time off request that waits for approval
        The following example creates a time off request for one day. The request is created in AWAITING_APPROVAL until an ApproveTimeOff or RejectTimeOff call decides it.

        >>> client.create_time_off(instance_id='12345678-1234-1234-1234-123456789012', user_id='87654321-4321-4321-4321-210987654321', shift_activity_id='11112222-3333-4444-5555-666677778888', start_at=1795424400, end_at=1795453200, description='Family event', approval_type='AWAIT_APPROVAL')
    """

    def _handler(
        req: "OperationRequest[capo_connectscheduling.types.create_time_off_request.CreateTimeOffRequest]",
    ) -> OperationResponse[
        "capo_connectscheduling.types.create_time_off_response.CreateTimeOffResponse"
    ]:
        import capo_connectscheduling._operations.amazon_connect_scheduling.create_time_off

        output, http_response = (
            capo_connectscheduling._operations.amazon_connect_scheduling.create_time_off.create_time_off(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_connectscheduling.types.create_time_off_request.CreateTimeOffRequest",
    ) -> dict[str, Any]:
        import capo_connectscheduling.types.create_time_off_request

        return (
            capo_connectscheduling.types.create_time_off_request.redact_sensitive(
                input_
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateTimeOff", redact_input=_redact_input),
    )
    input_: capo_connectscheduling.types.create_time_off_request.CreateTimeOffRequest = {
        "instance_id": instance_id,
        "user_id": user_id,
        "shift_activity_id": shift_activity_id,
        "start_at": start_at,
        "end_at": end_at,
        "approval_type": approval_type,
    }
    if description is not None:
        input_["description"] = description
    if rule_failure_action is not None:
        input_["rule_failure_action"] = rule_failure_action
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output