---
schema: rendered-html/v1
title: "Connection | Developer Portal for YouTrack and Hub Documentation"
source_url: https://www.jetbrains.com/help/youtrack/devportal/v1-Connection.html
generated_at: 2026-06-11T15:16:02.888432+00:00
---

Feedback

Thanks for your feedback!

Was this page helpful?

YesNo

Developer Portal for YouTrack and Hub

- Developer Portal
- Apps
- MCP Tools
- YouTrack Workflows
- JavaScript Workflow Quick Start Guide
- Create a Workflow
- Edit a Workflow
- Workflow Rule Types
- Transactions
- Use Cases for Workflows
- Web-based Workflow Editor
- Using an External Code Editor
- Default Workflows
- Custom Workflow Repository
- JavaScript Workflow Reference
- Rule-specific Properties
- Context
- Requirements
- Using the Workflow API
- Building Integrations with Slack
- Using REST API Methods in JavaScript Workflows
- Working with Dates and Times
- Working with Periods
- Localized Workflow Messages
- Troubleshooting Workflows
- Remote Debugger
- YouTrack Workflow API
- Change Log
- date-time
- entities
- http
- [Connection](v1-Connection.html)
- REQUEST\_TYPES
- Response
- license
- notifications
- search
- strings
- workflow
- YouTrack Import Scripts
- YouTrack Form API
- YouTrack REST API
- Hub REST API

1. YouTrack Workflows
2. JavaScript Workflow Reference
3. YouTrack Workflow API
4. http
5. [Connection](#0)

# Connection﻿

Last modified: 07 May 2026

Main class that is used to establish a connection and send requests to target sites.

```
// Gets the content of a PasteBin paste, assuming that we have received its key (`pasteBinKey`) in a prior request.
const connection = new http.Connection('http://pastebin.com/raw/');
connection.addHeader({name: 'Content-Type', value: 'text/plain'});
const response = connection.getSync(pasteBinKey, '');
if (response && response.code === 200) {
  let text = '';
  response.headers.forEach(function(header) {
    text += header.name + ': ' + header.value + '\n';
  });
  text += '\n' + response.response;
  issue.addComment(text);
}
```

## Properties﻿

| Name | Type | Description |
| headers | Array.<{name: String, value: String}> | A list of headers. |
| url | string | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |

## Constructors﻿

### Connection﻿

```
Connection(url, sslKeyName, timeout)
```

Creates an object that lets you establish a connection with a target site.

**Parameters**

| Name | Type | Description |
| url | string | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |
| sslKeyName | string | Optional name of the SSL key that is used to establish a secure connection. If you don't want to specify this parameter, pass 'null'. |
| timeout | int | Optional parameter that specifies the connection timeout for outgoing HTTP requests in milliseconds. |

**See Also**

- doSync

## Methods﻿

### addHeader﻿

```
addHeader(header, value)
```

Adds a new header to the current connection. The `value` parameter can also contain references to secrets stored in the settings for a YouTrack app.

**Parameters**

| Name | Type | Description |
| header | Object, string | A header object with the structure {name: string, value: string}. If the value parameter is specified separately, the provided string is used as the name of the header. |
| value | string | The value that is assigned to the header. Only considered when the first parameter is specified as a string. |

**Return Value**

| Type | Description |
| Connection | The current connection object. |

### basicAuth﻿

```
basicAuth(login, password)
```

Adds an authorization header with the value returned by the Base64.encode(login + ':' + password) function. The `password` parameter also accepts references to secrets stored in the settings for a YouTrack app.

**Parameters**

| Name | Type | Description |
| login | String | The login to use for the authorization request. |
| password | String | The password to use for the authorization request. |

**Return Value**

| Type | Description |
| Connection | The current connection object. |

### bearerAuth﻿

```
bearerAuth(token)
```

Adds an authorization header with the value in "Bearer" format ('Bearer ' + token). The `token` parameter also accepts references to secrets stored in the settings for a YouTrack app.

**Parameters**

| Name | Type | Description |
| token | String | The token to use for the authorization request. |

**Return Value**

| Type | Description |
| Connection | The current connection object. |

### connectSync﻿

```
connectSync(uri, queryParams)
```

Executes a synchronous CONNECT request.

**Parameters**

| Name | Type | Description |
| uri | string | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### deleteAsync﻿

```
deleteAsync(uri, queryParams, handlerName)
```

Schedules an asynchronous DELETE request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. |
| queryParams | Array, Object | The query parameters. |
| handlerName | string | The name of the async function to call with the response. |

### deleteSync﻿

```
deleteSync(uri, queryParams)
```

Executes a synchronous DELETE request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### doAsync﻿

```
doAsync(requestType, uri, queryParams, payload, handlerName)
```

Schedules an asynchronous HTTP request. The request is executed after the current transaction commits, and the response is passed to the named async function handler.

**Parameters**

| Name | Type | Description |
| requestType | string | A valid HTTP request type. |
| uri | string | A relative URI. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. |
| payload | string, Object | The payload to be sent in the request. |
| handlerName | string | The name of the async function to call with the response. |

### doSync﻿

```
doSync(requestType, uri, queryParams, payload)
```

Sends a synchronous HTTP request. Note that instead of passing a proper request type with this method, there are dedicated methods that correspond to each request type that you can call directly. For example, getSync or postSync.

**Parameters**

| Name | Type | Description |
| requestType | string | A valid HTTP request type. For a list of supported request types, see REQUEST\_TYPES. |
| uri | string | A relative URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}> | The query parameters. |
| payload | string, Array, Object | The payload to be sent in the request. |

**Return Value**

| Type | Description |
| Response | An object that represents the HTTP response. |

### getAsync﻿

```
getAsync(uri, queryParams, handlerName)
```

Schedules an asynchronous GET request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. |
| queryParams | Array, Object | The query parameters. |
| handlerName | string | The name of the async function to call with the response. |

### getSync﻿

```
getSync(uri, queryParams)
```

Executes a synchronous GET request.

**Parameters**

| Name | Type | Description |
| uri | String | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### headSync﻿

```
headSync(uri, queryParams)
```

Executes a synchronous HEAD request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### optionsSync﻿

```
optionsSync(uri, queryParams)
```

Executes a synchronous OPTIONS request.

**Parameters**

| Name | Type | Description |
| uri | string | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### patchAsync﻿

```
patchAsync(uri, queryParams, payload, handlerName)
```

Schedules an asynchronous PATCH request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. |
| queryParams | Array, Object | The query parameters. |
| payload | string, Object | The payload to be sent in the request. |
| handlerName | string | The name of the async function to call with the response. |

### patchSync﻿

```
patchSync(uri, queryParams, payload)
```

Executes a synchronous PATCH request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. |
| payload | string | The payload to be sent in the request. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### postAsync﻿

```
postAsync(uri, queryParams, payload, handlerName)
```

Schedules an asynchronous POST request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. |
| queryParams | Array, Object | The query parameters. |
| payload | string, Object | The payload to be sent in the request. |
| handlerName | string | The name of the async function to call with the response. |

### postSync﻿

```
postSync(uri, queryParams, payload)
```

Executes a synchronous POST request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
| payload | string, Object | The payload to be sent in the request. For posting attachment files from YouTrack to a third-party application, pass the payload as an object, set its `type` value to 'multipart/form-data', and pass the attachments in `parts`. For each part, `name`, `size`, `fileName`, and `content` values are required. See an example of such a request below. For details, see Posting Binary Content with multipart/form-data Type |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

**Example**

```
const attachment = issue.attachments.first();
connection.postSync('issues/' + issue.id + '/attachments', [], {
    type: 'multipart/form-data',
    parts: [
        {
            // These four fields are required for each part.
            // Optionally, you can also set the `contentType` value individually for each part.
            name: 'my-part-name',
            size: attachment.size,
            fileName: 'filename',
            content: attachment.content
        }
    ]
});
```

### putAsync﻿

```
putAsync(uri, queryParams, payload, handlerName)
```

Schedules an asynchronous PUT request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. |
| queryParams | Array, Object | The query parameters. |
| payload | string, Object | The payload to be sent in the request. |
| handlerName | string | The name of the async function to call with the response. |

### putSync﻿

```
putSync(uri, queryParams, payload)
```

Executes a synchronous PUT request.

**Parameters**

| Name | Type | Description |
| uri | string | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
| queryParams | Array.<{name: String, value: String}>, Object | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
| payload | string | The payload to be sent in the request. |

**Return Value**

| Type | Description |
| Response | An object that represents an HTTP response. |

### setHeader﻿

```
setHeader(header, value)
```

Sets a header to the current connection. If the specified header already exists, its value is updated. The `value` parameter can also contain references to secrets stored in the settings for a YouTrack app.

**Parameters**

| Name | Type | Description |
| header | Object, string | A header object with the structure {name: string, value: string}. If the value parameter is specified separately, the provided string is used as the name of the header. |
| value | string | The value that is assigned to the header. Only considered when the first parameter is specified as a string. |

**Return Value**

| Type | Description |
| Connection | The current connection object. |

- [Connection](/help/youtrack/devportal/v1-Connection.html)
- [Properties](/help/youtrack/devportal/v1-Connection.html#properties)
- [Constructors](/help/youtrack/devportal/v1-Connection.html#constructors)
- [Connection](/help/youtrack/devportal/v1-Connection.html#Connection)
- [Methods](/help/youtrack/devportal/v1-Connection.html#methods)
- [addHeader](/help/youtrack/devportal/v1-Connection.html#addHeader)
- [basicAuth](/help/youtrack/devportal/v1-Connection.html#basicAuth)
- [bearerAuth](/help/youtrack/devportal/v1-Connection.html#bearerAuth)
- [connectSync](/help/youtrack/devportal/v1-Connection.html#connectSync)
- [deleteAsync](/help/youtrack/devportal/v1-Connection.html#deleteAsync)
- [deleteSync](/help/youtrack/devportal/v1-Connection.html#deleteSync)
- [doAsync](/help/youtrack/devportal/v1-Connection.html#doAsync)
- [doSync](/help/youtrack/devportal/v1-Connection.html#doSync)
- [getAsync](/help/youtrack/devportal/v1-Connection.html#getAsync)
- [getSync](/help/youtrack/devportal/v1-Connection.html#getSync)
- [headSync](/help/youtrack/devportal/v1-Connection.html#headSync)
- [optionsSync](/help/youtrack/devportal/v1-Connection.html#optionsSync)
- [patchAsync](/help/youtrack/devportal/v1-Connection.html#patchAsync)
- [patchSync](/help/youtrack/devportal/v1-Connection.html#patchSync)
- [postAsync](/help/youtrack/devportal/v1-Connection.html#postAsync)
- [postSync](/help/youtrack/devportal/v1-Connection.html#postSync)
- [putAsync](/help/youtrack/devportal/v1-Connection.html#putAsync)
- [putSync](/help/youtrack/devportal/v1-Connection.html#putSync)
- [setHeader](/help/youtrack/devportal/v1-Connection.html#setHeader)

httpREQUEST\_TYPES

- Privacy & Security
- Terms Of Use
- Trademarks
- Legal

Copyright © 2000–2026 JetBrains s.r.o.
