---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
  - property: og:type
    content: article
  - property: article:section
    content: Интеграция с другими сервисами
  - property: og:title
    content: Интеграция Трекера с Cloud Functions
  - property: article:tag
    content: Техническая инструкция
alternate:
  - https://yandex.ru/support/tracker/en/tutorials/tracker-cloud-function.md
  - https://yandex.ru/support/tracker/ru/tutorials/tracker-cloud-function.md
  - href: en/tutorials/tracker-cloud-function.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/support/tracker/en/llms.txt


# Integrating Yandex Tracker with Cloud Functions

Learn how to integrate Yandex Tracker automation tools with Cloud Functions. The example shows how to calculate the total time spent on a parent issue from all its sub-issues.

To configure the total time spent value of a parent issue to automatically update whenever this value changes in any of its child sub-issues:

1. [Register the application](#register-app).
1. [Get an application access token](#get-token).
1. [Get an organization ID to access the API](#get-tracker-id).
1. [Create a Cloud Functions function](#create-function).
1. [Set up a trigger](#setup-trigger).
1. [Test out automatic data updates](#test-updates).

## Getting started {#before-you-begin}

{% note info "" %}

To run the scenario, you will need:

* Yandex Cloud billing account.
* A Yandex Tracker account that belongs to an organization connected to Yandex Cloud with a [role](https://yandex.cloud/en/docs/organization/security/index#service-roles) of at least `organization-manager.admin`.

{% endnote %}

<!-- source: en/_includes/before-you-begin.md -->
Sign up for Yandex Cloud and create a billing account:

1. Go to the [management console](https://console.cloud.yandex.com) and log in to Yandex Cloud or create an account if you do not have one yet.
1. On the **[Billing](https://billing.cloud.yandex.com/)** page, make sure you have a [billing account](https://yandex.cloud/en/docs/billing/concepts/billing-account) activated and its status is `ACTIVE` or `TRIAL_ACTIVE`. If you do not have a billing account, [create one](https://yandex.cloud/en/docs/billing/quickstart).

If you have an active billing account, you can create or select a folder on the [cloud page](https://console.yandex.cloud/cloud) to host your infrastructure.

[Learn more about clouds and folders](https://yandex.cloud/en/docs/resource-manager/concepts/resources-hierarchy).
<!-- endsource: en/_includes/before-you-begin.md -->

### Required paid resources {#paid-resources}

The infrastructure maintenance fee covers the cost of using this function (see [Cloud Functions pricing](https://yandex.cloud/en/docs/functions/pricing)).

If you no longer need the resources you created, [delete them](#clear-out).

## Register the application {#register-app}

<!-- source: en/api-ref/access.md -->
{% note warning "" %}

If you use a federated or service account, authenticate using an [IAM token](#iam-token).

{% endnote %}


To get a token:



1. Go to [https://oauth.yandex.com/](https://oauth.yandex.com/).

1. On the **Your applications** page, click ![](../_assets/svg/add-icon.svg)</svg> **Create**.

1. In the window that opens, select the **For API access or debugging** option and click **Proceed to creation**.

1. Specify the application name and contact email.


1. Add permissions to access user data. To select a permission, start typing its name in the **Access name** field:
   * **Write to tracker (tracker:write)** — all data operations: create, delete, edit.
   * **Read from tracker (tracker:read)** — read-only access to data.

1. Click **Create application**.

1. In the [Yandex OAuth](https://oauth.yandex.com/) personal account, select the previously created application and copy its ID from the **ClientID** field.


1. Generate the token request link:

   ```
   https://oauth.yandex.com/authorize?response_type=token&client_id=<application_id>
   ```

1. Log in to the account on whose behalf you will work with the API and go to the generated link. 

   A sequence of characters will appear on the page — this is the OAuth token. Copy it and save it.



To check if you have access to the API, execute the [request for information about the current user](https://yandex.ru/support/tracker/en/api-ref/users/get-user-info.md). If access was not obtained, the request will return a response with code `401 Unauthorized`.

Example request for information about the current user using curl:

<!-- source: en/api-ref/_includes/curl-request.md -->
{% list tabs %}

- Unix

   ```bash
   curl -X GET 'https://api.tracker.yandex.net/v3/myself' \
        -H 'Authorization: OAuth y0__xAbc******' \
        -H 'X-Org-ID: 1234******'
   ```

- Windows

   ```bash
   curl -X GET "https://api.tracker.yandex.net/v3/myself" ^
        -H "Authorization: OAuth y0__xAbc******" ^
        -H "X-Org-ID: 1234******"
   ```

{% endlist %}
<!-- endsource: en/api-ref/_includes/curl-request.md -->
<!-- endsource: en/api-ref/access.md -->

## Get an application access token {#get-token}

1. In the browser, go to:
	```
	https://oauth.yandex.ru/authorize?response_type=token&client_id=<app_ID>
	```
	Where the `client_id` parameter value is the application ID from the **ClientID** field on the application details page from the previous step.
1. Wait for the page to load and copy the token.
1. Save the token. You will need it to create a function.

## Get an organization ID to access the API {#get-tracker-id}

1. Go to [Tracker](https://tracker.yandex.ru/). Click **Log in to Tracker**.
1. In the right-hand panel, click **Administration**.
1. Under **Access and payment**, click **Organizations**.
1. Under **Yandex 360 for businesses**, copy and save your organization ID. You'll need it to create a function.

## Create a Cloud Functions function {#create-function}

1. Go to the [management console](https://console.cloud.yandex.com).
1. In the top-left corner, click ![](../_assets/console-icons/dots-9.svg) **All services**.
1. Select **Serverless computing** → **Cloud Functions**.
1. Click **Create function**.
1. Enter a function name, e.g., `timeupdater`.
1. Click **Create**.
1. In the **Editor** window that opens, select `Python / 3.9` runtime environment.
1. Click **Next**.
1. In the **Method** field, click **ZIP archive**.
1. Attach a [test archive](https://github.com/yandex-cloud-examples/yc-tracker-summarize-spent/blob/main/build/tracker-summarize-spent.zip).
1. In the **Entry point** field, specify `index.handler`.
1. Go to **Parameters** and in the **Environment variables** field, add:
   * `ORG`: Yandex 360 for Business organization ID
   * `TOKEN`: Application access token
1. Click **Save changes**.
1. Wait for the page to load. Next, in the **Link to invoke** field, copy and save the function invocation link.
	Here is an example of such a link:
	```
	https://functions.yandexcloud.net/d4e94uav3108********
	```
1. Enable the **Public function** option.

## Set up a trigger {#setup-trigger}

### Create a queue

1. <!-- source: en/_includes/create-queue.md -->
   On the left panel, click ![](../_assets/svg/queues-ni.svg) **Queues** → **Create queue**. {#create-web}
   <!-- endsource: en/_includes/create-queue.md -->
1. Select a queue template, e.g., **Basic development model**.
1. Enter a name, e.g., `Function Test`.
1. Click **Create**.

### Create a trigger

1. In the top-right corner of the queue page, click ![](../_assets/svg/settings.svg)</svg> **Queue settings**.
1. On the left-hand panel, select **Automation** → **Triggers** and click **Create trigger**.
1. In the **Name** field, enter a trigger name, e.g., `timeupdater`.
1. Under **Conditions**, select **Time Tracking** → **Time Spent**.
1. Under **Trigger actions**, select **HTTP request**.
1. In the form that opens, in the **Address** field, enter:
	```
	https://functions.yandexcloud.net/<function_ID>?id={{issue.key}}
	```
	Where `https://functions.yandexcloud.net/<function_ID>` is the function invocation link you saved when creating the function.
	Example:
	```
	https://functions.yandexcloud.net/d4e94uav3108********?id={{issue.key}}
	```
1. Click **Create**.

## Test out automatic data updates {#test-updates}

### Create issues

1. Create a parent issue whose total time spent across all sub-issues will be calculated:
	1. On the `Function Test` queue page, click **Create issue**.
	1. In the form that opens, in the **Issue name** field, enter an issue name, e.g., `Parent Task`.
	1. Click **Create**.
1. Create sub-issues:
	1. In the top right corner of the `Parent Task` issue page, select **Add sub-issue** in the **Actions** menu.
	1. In the form that opens, in the **Issue name** field, enter a sub-issue name, e.g., `Subtask-1`.
	1. In the same way, create another sub-issue or multiple sub-issues named `Subtask-2`, `Subtask-3`, and so on.

### Enter time spent values for the sub-issues

1. Go to the `Subtask-1` sub-issue page and select **Add time spent** from the **Actions** menu in the top right corner.
1. In the window that opens, specify any time value in the **Time Spent** field. For example, you can enter `1h25m`.
1. In the same way, add time spent values for the other sub-issues.

### Check if the function works correctly

1. Go to the `Parent Task` issue page.
1. In the issue properties, make sure that the **Time Spent** field under **Time Tracking** includes the time you specified in the sub-issue.

## How to delete the resources you created {#clear-out}

To stop paying for the resources you created, [delete the Cloud Functions function](https://yandex.cloud/en/docs/functions/operations/function/function-delete).
