Skip to content

send_bonus async

send_bonus(
    worker_id: CustomerId,
    bonus_amount: CurrencyAmount,
    assignment_id: EntityId,
    reason: String,
    *,
    config_overrides: Optional[AsyncMTurkClientConfig] = None,
    unique_request_token: Optional[IdempotencyToken] = None,
) -> SendBonusResponse

The SendBonus operation issues a payment of money from your account to a Worker. This payment happens separately from the reward you pay to the Worker when you approve the Worker's assignment. The SendBonus operation requires the Worker's ID and the assignment ID as parameters to initiate payment of the bonus. You must include a message that explains the reason for the bonus payment, as the Worker may not be expecting the payment. Amazon Mechanical Turk collects a fee for bonus payments, similar to the HIT listing fee. This operation fails if your account does not have enough funds to pay for both the bonus and the fees.

Parameters:

  • worker_id (CustomerId) –

    The ID of the Worker being paid the bonus.

  • bonus_amount (CurrencyAmount) –

    The Bonus amount is a US Dollar amount specified using a string (for example, "5" represents $5.00 USD and "101.42" represents $101.42 USD). Do not include currency symbols or currency codes.

  • assignment_id (EntityId) –

    The ID of the assignment for which this bonus is paid.

  • reason (String) –

    A message that explains the reason for the bonus payment. The Worker receiving the bonus can see this message.

  • unique_request_token (Optional[IdempotencyToken], default: None ) –

    A unique identifier for this request, which allows you to retry the call on error without granting multiple bonuses. This is useful in cases such as network timeouts where it is unclear whether or not the call succeeded on the server. If the bonus already exists in the system from a previous call using the same UniqueRequestToken, subsequent calls will return an error with a message containing the request ID.

Raises:

  • RequestError –

    Your request is invalid.

  • ServiceFault –

    Amazon Mechanical Turk is temporarily unable to process your request. Try your call again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_mturk/_services/async_m_turk.py
async def send_bonus(
    self,
    worker_id: "capo_mturk.types.customer_id.CustomerId",
    bonus_amount: "capo_mturk.types.currency_amount.CurrencyAmount",
    assignment_id: "capo_mturk.types.entity_id.EntityId",
    reason: "capo_mturk.types.string.String",
    *,
    config_overrides: Optional[AsyncMTurkClientConfig] = None,
    unique_request_token: Optional[
        "capo_mturk.types.idempotency_token.IdempotencyToken"
    ] = None,
) -> "capo_mturk.types.send_bonus_response.SendBonusResponse":
    """<p> The <code>SendBonus</code> operation issues a payment of money from your account to a Worker. This payment happens separately from the reward you pay to the Worker when you approve the Worker's assignment. The SendBonus operation requires the Worker's ID and the assignment ID as parameters to initiate payment of the bonus. You must include a message that explains the reason for the bonus payment, as the Worker may not be expecting the payment. Amazon Mechanical Turk collects a fee for bonus payments, similar to the HIT listing fee. This operation fails if your account does not have enough funds to pay for both the bonus and the fees. </p>

    Args:
        worker_id: <p>The ID of the Worker being paid the bonus.</p>
        bonus_amount: <p> The Bonus amount is a US Dollar amount specified using a string (for example, "5" represents $5.00 USD and "101.42" represents $101.42 USD). Do not include currency symbols or currency codes. </p>
        assignment_id: <p>The ID of the assignment for which this bonus is paid.</p>
        reason: <p>A message that explains the reason for the bonus payment. The Worker receiving the bonus can see this message.</p>
        unique_request_token: <p>A unique identifier for this request, which allows you to retry the call on error without granting multiple bonuses. This is useful in cases such as network timeouts where it is unclear whether or not the call succeeded on the server. If the bonus already exists in the system from a previous call using the same UniqueRequestToken, subsequent calls will return an error with a message containing the request ID.</p>

    Raises:
        capo_mturk.errors.request_error.RequestError: <p>Your request is invalid.</p>
        capo_mturk.errors.service_fault.ServiceFault: <p>Amazon Mechanical Turk is temporarily unable to process your request. Try your call again.</p>
        capo_mturk.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_mturk.types.send_bonus_request.SendBonusRequest]",
    ) -> AsyncOperationResponse[
        "capo_mturk.types.send_bonus_response.SendBonusResponse"
    ]:
        import capo_mturk._operations.m_turk_requester_service_v20170117.send_bonus

        (
            output,
            http_response,
        ) = await capo_mturk._operations.m_turk_requester_service_v20170117.send_bonus.async_send_bonus(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SendBonus")
    )
    input_: capo_mturk.types.send_bonus_request.SendBonusRequest = {
        "worker_id": worker_id,
        "bonus_amount": bonus_amount,
        "assignment_id": assignment_id,
        "reason": reason,
    }
    if unique_request_token is not None:
        input_["unique_request_token"] = unique_request_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output