Issue rewards 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 OAuth token with your own one.

toloka_client = toloka.
('AQC2AGAJgyNSA8CtpdO9MWy_QEB6s6kDjHUoElE', 'PRODUCTION');

3. Issue reward to Toloker

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

  • the ID of the Toloker you want to give the reward to
  • the reward 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 reward
from decimal import Decimal


new_bonus = toloka_client.
(toloka.user_bonus.
(

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 reward 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 reward which looks like this.

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

Complete code: Issue rewards to Tolokers

from decimal import Decimal
import toloka.client as toloka
toloka_client = toloka.TolokaClient('AQC2AGAJgyNSA8CtpdO9MWy_QEB6s6kDjHUoElE', '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

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