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.

#!/bin/bash
# Путь к списку пользователей
employees='./usrlist'
#Пример строки файла usrlist: email_firstname_lastname_middlename
# OAuth_Token
# Ссылка на формирование отладочного токена
# https://tech.yandex.ru/oauth/doc/dg/tasks/get-oauth-token-docpage/
TOKEN="bash!bash!bash!bash!bash!bash!bash!bash!"
# Пароль по умолчанию для всех сотрудников
PASS="superstrongpasswordforyou"
# Перебираем файл со списком пользователей
for i in $( cat $employees ); do
value=($(echo $i | tr "_" " "))
# Формируем поля для заполнения профиля
email="${value[0]}"
firstname="${value[1]}"
lastname="${value[2]}"
middlename="${value[3]}"
# Создаем сотрудника
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" 'https://api.directory.yandex.net/v6/users/' | grep HTTP
done

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" 'https://api.directory.yandex.net/v6/users/'

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:

Screenshot


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

Screenshot


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:

https://oauth.yandex.ru/authorize?response_type=token&client_id=<идентификатор приложения>

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: