How to connect YouTrack to Albato

YouTrack: Project management integrations
YouTrack
·
9/18/2023
·
3 min. read

YouTrack - everything in one place. Track tasks, manage projects, maintain a knowledge base, support your customers, collaborate, and deliver great products.

Available triggers

Triggers are the events that trigger the automation, All triggers run in real time, i,e, data is transferred in the moment the event occurs

  • Issue created
  • Issue updated

Available actions

Actions are what Albato performs when your automation is running, Actions also allow you to transfer data to other apps and systems

  • New issue
  • Update issue
  • Find an issue

Before setting up integrations with YouTrack, connect the tool to Albato.

To do this, go to the Apps section and click the Add a connection button.

Example.png

Select the app and click the Add a connection button.

YouTrack.png

Come up with a name for your connection.

Enter your Domain and API key.

Click the Continue button.

YouTrack (1).png

How to get API key

Go to your YouTrack account.

Either copy the ID from the browser address bar or enter the name of the workspace you used to create the account. Go to the list of system users, select the user who will access the integration, and open the Account Security tab.

Next, create a new token and copy its value.

YouTrack (2).png

Paste the token into the Albato connection field.

The first part of the connection is finished. To receive tickets from YouTrack, we need to create two more workflows in YouTrack, write our JS code there and insert the webhook from the connection into them.

Go to the Workflows tab.

YouTrack (3).png

Create a new Workflow.

YouTrack (4).png

Set a name for your Workflow

YouTrack (5).png

and select the rule:

YouTrack (6).png

Paste the following code:

const albatoHook = '{{albatoHook}}';
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const http = require('@jetbrains/youtrack-scripting-api/http');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');

function periodToHours(period) {
  return period ? (
    period.getMinutes() / 60 +
    (
      period.getHours() +
      period.getDays() * 8 +
      period.getWeeks() * 40
    )
  ) : 0;
}

function formatValue(value) {
  if (typeof value === 'object' && value !== null) {
    switch (value.$$type) {
      case 'User':
        value = value.fullName;
        break;
      default:
        if ('getPeriodType' in value) {
          value = periodToHours(value);
        } else if (value.constructor.name === 'ImmutableIterableWW') {
          const array = value;
          value = [];
          array.forEach(item => value.push(item.name));
        } else {
          value = value.name;
        }
    }
  }
  return value === undefined ? null : value;
}
exports.rule = entities.Issue.onChange({
  title: workflow.i18n('Send webhook to Albato'),
  guard: function(ctx) {
    return ctx.issue.becomesReported && ctx.issue.isReported;
  },
  action: function(ctx) {
    const issue = ctx.issue;
    const fields = {};
    for (let field in issue.fields) {
      fields[field] = formatValue(issue.fields[field]);
    }
    const tags = [];
    issue.tags.forEach(nameTag => tags.push(nameTag.name));
    const payload = {
      'event': 'newTicket',
      'ticketUrl': issue.url,
      'tags': tags,
      'id': issue.id,
      'summary': issue.summary,
      'description': issue.description,
      'projectId': issue.project.key,
      'project': issue.project.name,
      'dateCreate': issue.created,
      'dateUpdate': issue.updated,
      'fields': fields,
    };
    console.log(issue.tags);
    const connection = new http.Connection(albatoHook, null, 2000);
    connection.addHeader('content-type', 'application/json');
    const response = connection.postSync('', null, payload);
    if (!response.isSuccess) {
      console.warn('Failed to post webhook to Albato. Details: ' + response.toString());
    }
  },
});

This code catches only the creation of tasks, and the following code catches changes to tasks. You can work in one rule, or you can create an additional rule and add the following code to it:

const albatoHook = '{{albatoHook}}';
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const http = require('@jetbrains/youtrack-scripting-api/http');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');

function periodToHours(period) {
  return period ? (
    period.getMinutes() / 60 +
    (
      period.getHours() +
      period.getDays() * 8 +
      period.getWeeks() * 40
    )
  ) : 0;
}

function formatValue(value) {
  if (typeof value === 'object' && value !== null) {
    switch (value.$$type) {
      case 'User':
        value = value.fullName;
        break;
      default:
        if ('getPeriodType' in value) {
          value = periodToHours(value);
        } else if (value.constructor.name === 'ImmutableIterableWW') {
          const array = value;
          value = [];
          array.forEach(item => value.push(item.name));
        } else {
          value = value.name;
        }
    }
  }
  return value === undefined ? null : value;
}
exports.rule = entities.Issue.onChange({
  title: workflow.i18n('Send webhook to Albato'),
  guard: function(ctx) {
    return !ctx.issue.becomesReported && ctx.issue.isReported;
  },
  action: function(ctx) {
    const issue = ctx.issue;
    const fields = {};
    for (let field in issue.fields) {
      fields[field] = formatValue(issue.fields[field]);
    }
    const tags = [];
    issue.tags.forEach(nameTag => tags.push(nameTag.name));
    const payload = {
      'event': 'changedTicket',
      'ticketUrl': issue.url,
      'tags': tags,
      'id': issue.id,
      'summary': issue.summary,
      'description': issue.description,
      'projectId': issue.project.key,
      'project': issue.project.name,
      'dateCreate': issue.created,
      'dateUpdate': issue.updated,
      'fields': fields,
    };
    console.log(issue.tags);
    const connection = new http.Connection(albatoHook, null, 2000);
    connection.addHeader('content-type', 'application/json');
    const response = connection.postSync('', null, payload);
    if (!response.isSuccess) {
      console.warn('Failed to post webhook to Albato. Details: ' + response.toString());
    }
  },
});

Important!

Now you have to replace in each rule where you inserted the code, in the very first constant "const albatoHook = '{{albatoHook}}';", the value {{albatoHook}}, with the actual webhook from the previously created connection. Copy the webhook from the connection you created to Albato.

YouTrack (8).png

Insert a webhook into each process you create:

YouTrack (7).png

Next, you need to link your Workflow to the project you need. To do this, go back to your Workflow list, select the Workflow you created and link it to the projects:

YouTrack (9).png

Done! Now you can use the YouTrack in your integrations.


YouTrack

Related articles

Show more
Slack, CRM, and Task Manager Integrations: The Key to a Smooth Workflow
CRM
4 min. read

Slack, CRM, and Task Manager Integrations: The Key to a Smooth Workflow

No more manually creating tasks and notes, and no more wasting valuable time. With the help of automation, you can stay organized and focus on what matters most.

How to set up HubSpot Integrations with 800+ Apps
HubSpot
2 min. read

How to set up HubSpot Integrations with 800+ Apps

Learn how to integrate HubSpot with 800+ apps through Albato. Step-by-step guide to HubSpot integration and connecting your favorite business tools.

What Are White-Label Integrations for SaaS
7 min. read

What Are White-Label Integrations for SaaS

In this article, we explain what white-label integrations for SaaS are, explore their benefits and drawbacks.

Smarter Triggers, More Actions & Seamless Integrations
2 min. read

Smarter Triggers, More Actions & Seamless Integrations

Explore what’s new in Albato: features, apps, and improvements

In-house vs. Unified API vs. Embedded iPaaS: Key Differences & Best Use Cases
8 min. read

In-house vs. Unified API vs. Embedded iPaaS: Key Differences & Best Use Cases

In this article, you will learn the key differences between in-house integration development, Unified APIs and Embedded iPaaS to choose the best strategy for your SaaS product.

What the Ansoff Growth Matrix Is and How to Use It
8 min. read

What the Ansoff Growth Matrix Is and How to Use It

In this article, you will learn the definition of the Ansoff Growth Matrix, how it works, and how to use it for strategic planning in your business.

White-Label Albato Embedded vs. Zapier Embed: Solution Comparison
6 min. read

White-Label Albato Embedded vs. Zapier Embed: Solution Comparison

In this article, you will learn about the features and pricing fo Albato Embedded vs Zapier to help you find the best white-label integration solution for your needs.

Big News for AI Enthusiasts
2 min. read

Big News for AI Enthusiasts

Explore what’s new in Albato: features, apps, and improvements

Top 15 Tools for Outreach 2025
20 min. read

Top 15 Tools for Outreach 2025

In this article, you will find 15 top tools for outreach that help with contact enrichment, lead scoring, and more.

Product Updates We're Excited About
3 min. read

Product Updates We're Excited About

Explore what’s new in Albato: features, apps, and improvements!

How to Automate Repetitive Tasks in Your Business with No-Code Automation
8 min. read

How to Automate Repetitive Tasks in Your Business with No-Code Automation

In this article, you will learn about the benefits of no-code automation for business, which tools to use, and how to implement automation in your company.

Product-Led Growth: 4 Strategies and Implementation Guide
Embedded
13 min. read

Product-Led Growth: 4 Strategies and Implementation Guide

In this article, you will learn what product-led growth (PLG) is and how it drives user acquisition, retention, and scalability on real-life examples.