Import to J. Connect from user list file via API

Faced the problem of “not finding” the actual script for the mass creation of employees.

The problem is connected with the transition of Yandex from PDD (Mail for a domain), to Yandex.Connect with the new version of the API.

The scripts that came across to me were written only for the "old" version of the API, and therefore are considered non-working irrelevant.

Therefore, here’s the current simple little creak for today, for the mass creation of “Employees” in the organization.

# Путь к списку пользователей
#Пример строки файла usrlist: email_firstname_lastname_middlename
# OAuth_Token
# Ссылка на формирование отладочного токена
# Пароль по умолчанию для всех сотрудников
# Перебираем файл со списком пользователей
for i in $( cat $employees ); do
value=($(echo $i | tr "_" " "))
# Формируем поля для заполнения профиля
# Создаем сотрудника
curl -i -X POST -H 'Content-type: application/json' -d '{"department_id": 1, "password": "'$PASS'", "nickname": "'$email'", "name": {"first": "'$firstname'", "last": "'$lastname'", "middle": "'$middlename'"}}' -H "Authorization: OAuth $TOKEN" '' | grep HTTP

If you have several departments in your organization, then in the line:

curl -i -X POST -H 'Content-type: application/json' -d '{"department_id": 1, "password": "'$PASS'", "nickname": "'$email'", "name": {"first": "'$firstname'", "last": "'$lastname'", "middle": "'$middlename'"}}' -H "Authorization: OAuth $TOKEN" ''

There is a parameter:, "department_id": 1we are interested in the number, “1”, this is the default department “All employees”. When creating a new department (regardless of name), it will be “2”, respectively, with subsequent ones.

Now about how to get debugging OAuth-Token.

For the script applications to work with Yandex services, which uses the OAuth 2.0 authorization protocol, there is a debugging token, which we will use. After use, the debug token can be revoked, and the application can be deleted.

We go to the Yandex OAuth page to create a new application (By the way, we need administrator rights!).

I selected the following permissions for the application:


Next, you need to select the platform and click "Substitute URL for development":


After all the torment, you can return to Yandex OAuth and see our application, go into it and we are interested in the line “ID”, take the number-letter value, copy it to this line:<идентификатор приложения>

Then, on the page that opens, click the Confirm button to allow access.
voila , this is your OAuth_Token.

Finally: if you are interested in additional user attributes such as (date of birth, his gender, alliases, phones), then feel free to read the Documentation , there is quite accessible information for the basic use of this api.
: wq

Also popular now: