API access
To access the Yandex Wiki API, you can use one of these authorization methods:
-
OAuth 2.0 protocol. Can be used in both Yandex 360 for Business and Yandex Cloud Organization organizations. For more information, see Get access to the API using the OAuth protocol.
-
IAM token. Can only be used in Yandex Cloud organizations. For more information, see Access the API with an IAM token.
You can't use a Yandex Cloud service account for authorization in the Yandex Wiki API. Send requests only from a user account.
In Yandex Wiki API requests, specify the following headers:
-
Host: api.wiki.yandex.net -
Authorization header:
-
Authorization: OAuth <OAuth_token>— when using the OAuth 2.0 protocol. -
Authorization: Bearer <IAM_token>— when using an IAM token.
-
-
Organization ID:
X-Org-Id— for Yandex 360 for Business organizations.X-Cloud-Org-Id— for Yandex Cloud Organization organizations.
To find your organization ID, open Yandex Tracker, go to Admin settings → Organizations, and copy the ID field value.
Example:
Host: api.wiki.yandex.net Authorization: Bearer t1.ab123cd45***************** X-Org-Id: bpfv7***************
Get access to the API using the OAuth protocol
To access Yandex Wiki API, you need to obtain an OAuth token. Use the obtained token in the Authorization header when making requests to Yandex Wiki API.
This token grants permissions that mirror those of the user account in Wiki. For example, if the user doesn't have permission to edit a page, they won't be able to make the corresponding API requests.
To get a token:
-
Click the link https://oauth.yandex.ru/.
-
On the Your apps page, click
Create. -
In the window that opens, select For API access or debugging and click Create new token.
-
Enter the app name and contact email.
-
Add permissions for accessing user data. To select a permission, start typing its name in the Permission name field:
-
Запись в Вики (wiki:write) — все операции с данными: создание, удаление, редактирование.
-
Чтение из Вики (wiki:read) — только чтение данных.
-
-
Click Create app.
-
In your Yandex OAuth account, select the previously created application and copy its ID from the ClientID field.
-
Next, generate a link to request a token:
https://oauth.yandex.ru/authorize?response_type=token&client_id=<application_ID> -
Log in to the account which you'll be using to access the API, then follow the generated link.
You'll see a sequence of characters appear on the page — that's your OAuth token. Copy and save it.
See how to set up your app in Yandex ID Help:
To check if you have access to the API, send any request. If no access permission is granted, you will get a response with the 401 Unauthorized code.
For example, you can request information about mypage using curl:
curl -X GET 'https://api.wiki.yandex.net/v1/pages?slug=mypage' \
-H 'Authorization: OAuth ABC-def12GH_******' \
-H 'X-Org-Id: bpfv7***************'
curl -X GET "https://api.wiki.yandex.net/v1/pages?slug=mypage" ^
-H "Authorization: OAuth ABC-def12GH_******" ^
-H "X-Org-Id: bpfv7***************"
Access the API with an IAM token
If you're using Wiki as part of a Yandex Cloud organization, you can authorize with the API using an IAM token.
An IAM token is a unique sequence of characters issued to a user after authentication. The user needs this token to authorize with the Yandex Wiki API and access resources. Read more about this authentication method in the documentation of the identification and access control service.
The IAM token is valid for no more than 12 часов and is limited by the cookie lifetime for the federation. When the token expires, the 401 Unauthorized error is returned.