Issue bonuses to Tolokers

Additionally reward Tolokers who completed their tasks better than others.

Steps to follow

1. Import Toloka-Kit

Connect the Toloka-Kit library to your script.

import toloka.client as toloka

2. Instantiate TolokaClient

Replace the sample API key with your own one.

toloka_client = toloka.
TolokaClient
('PlaceYourRealApiKey_Here', 'PRODUCTION');

3. Issue bonus to Toloker

Now create the bonus for the Toloker. For this, you need the following information:

  • the ID of the Toloker you want to give the bonus to
  • the bonus amount in U.S. dollars
  • a public title and a message the Toloker will receive together with the bonus
  • the ID of the Toloker response for which you assign the bonus
from decimal import Decimal


new_bonus = toloka_client.
create_user_bonus
(toloka.user_bonus.
UserBonus
(

user_id='a1b0b42923c429daa2c764d7ccfc364d',

amount=Decimal('0.50'),
public_title={'EN': 'Perfect job!'}
public_message={'EN': 'You are the best!'}
assignment_id='000015fccc--63bfc4c358d7a46c32a7b233'
))

4. Display issued bonus info

The create_user_bonus() request will return the UserBonus class object. You can use its attributes to print the information you need.

print(new_bonus.created)

You should get an output with the date and time when you issued the bonus which looks like this.

2023-01-12 13:45:36.767000+00:00

Complete code: Issue bonuses to Tolokers

from decimal import Decimal
import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
new_bonus = toloka_client.create_user_bonus(toloka.user_bonus.UserBonus(
user_id='a1b0b42923c429daa2c764d7ccfc364d',
amount=Decimal('0.50'),
public_title={'EN': 'Perfect job!'},
public_message={'EN': 'You are the best!'},
assignment_id='000015fccc--63bfc4c358d7a46c32a7b233'
))
print(new_bonus.created)
List of classes and methods used in this recipe

See also

Last updated: February 7, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming