Connection
Represents an HTTP connection that sends requests to a target site from workflows, apps, and import scripts.
Properties
Name | Type | Description |
|---|---|---|
headers | Array.<{name: String, value: String}> | The headers added to the connection. |
url | string | The base URL of the target site. If empty, specify an absolute URL in each request method. |
Constructors
Connection
Creates a connection to a target site.
Parameters
Name | Type | Description |
|---|---|---|
url | string | The base URL of the target site. If empty, specify an absolute URL in each request method. |
sslKeyName | string | The optional name of the SSL key used to establish a secure connection. To omit this parameter, pass |
timeout | int | The optional timeout, in milliseconds, for outgoing HTTP requests. |
See Also
Quick Example
Request Styles
Style | Methods | Behavior |
|---|---|---|
Synchronous | The request completes during the current execution and returns a Response. | |
Asynchronous | The request runs after the current transaction commits. YouTrack passes the response to a named async function. |
Methods
addHeader
Adds a header to the connection. The value parameter can also reference a secret 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}.When the
valueparameter is specified separately, this string is used as the header name.value
string
The value to assign to the header. This parameter is used only when
headeris a string.- Return Value
Type
Description
Connection
The current Connection object.
basicAuth
Adds a Basic authorization header generated from the specified login and password. The password parameter can also reference a secret stored in the settings for a YouTrack app.
- Parameters
Name
Type
Description
login
String
The login for Basic authentication.
password
String
The password for Basic authentication.
- Return Value
Type
Description
Connection
The current Connection object.
bearerAuth
Adds a Bearer authorization header for the specified token. The token parameter can also reference a secret stored in the settings for a YouTrack app.
- Parameters
Name
Type
Description
token
String
The token for Bearer authentication.
- Return Value
Type
Description
Connection
The current Connection object.
connectSync
Executes a synchronous CONNECT request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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
The HTTP response.
deleteAsync
Schedules an asynchronous DELETE request.
Available since 2026.2
- Parameters
Name
Type
Description
uri
string
The request URI.
queryParams
Array, Object
The query parameters.
handlerName
string
The name of the async function that handles the response.
deleteSync
Executes a synchronous DELETE request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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
The HTTP response.
doAsync
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. The handler must be declared in the asyncFunctions property of the rule or HTTP handler. Inside the handler, the response is available as the response property of the context object. It provides the same properties and methods as Response.
Available since 2026.2
- 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 content to send in the request.
handlerName
string
The name of the async function that handles the response.
doSync
Sends a synchronous HTTP request of the specified type. For common request types, you can call a dedicated method such as getSync() or postSync() instead.
- 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 combines the URL passed to the Connection constructor with this string.
If the constructor URL is empty, specify the absolute URL of the target site.
queryParams
Array.<{name: String, value: String}>
The query parameters.
payload
string, Array, Object
The content to send in the request.
- Return Value
Type
Description
The HTTP response.
getAsync
Schedules an asynchronous GET request.
Available since 2026.2
- Parameters
Name
Type
Description
uri
string
The request URI.
queryParams
Array, Object
The query parameters.
handlerName
string
The name of the async function that handles the response.
getSync
Executes a synchronous GET request.
- Parameters
Name
Type
Description
uri
String
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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
The HTTP response.
headSync
Executes a synchronous HEAD request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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
The HTTP response.
optionsSync
Executes a synchronous OPTIONS request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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
The HTTP response.
patchAsync
Schedules an asynchronous PATCH request.
Available since 2026.2
- Parameters
Name
Type
Description
uri
string
The request URI.
queryParams
Array, Object
The query parameters.
payload
string, Object
The content to send in the request.
handlerName
string
The name of the async function that handles the response.
patchSync
Executes a synchronous PATCH request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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 content to send in the request.
- Return Value
Type
Description
The HTTP response.
postAsync
Schedules an asynchronous POST request.
Available since 2026.2
- Parameters
Name
Type
Description
uri
string
The request URI.
queryParams
Array, Object
The query parameters.
payload
string, Object
The content to send in the request.
handlerName
string
The name of the async function that handles the response.
postSync
Executes a synchronous POST request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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 content to send in the request.
For posting attachment files from YouTrack to a third-party application, pass the payload as an object, set its
typevalue tomultipart/form-data, and pass the attachments inparts.For each part,
name,size,fileName, andcontentvalues are required.For details and an example, see Posting Binary Content with multipart/form-data Type.
- Return Value
Type
Description
The 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
Schedules an asynchronous PUT request.
Available since 2026.2
- Parameters
Name
Type
Description
uri
string
The request URI.
queryParams
Array, Object
The query parameters.
payload
string, Object
The content to send in the request.
handlerName
string
The name of the async function that handles the response.
putSync
Executes a synchronous PUT request.
- Parameters
Name
Type
Description
uri
string
The request URI.
The complete URL combines the URL passed to the Connection constructor with this string.
If the constructor URL 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 content to send in the request.
- Return Value
Type
Description
The HTTP response.
setHeader
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
valueparameter is specified separately, the provided string is used as the name of the header.value
string
The value to assign to the header. This parameter is used only when
headeris a string.- Return Value
Type
Description
Connection
The current Connection object.