Host API
Host API is the supplementary API that supports communication between different parts of an app and YouTrack.
How to Use the Host API
When you want your widget to send HTTP requests to YouTrack or communicate with it using any of the YouTrack APIs, you must include a script that registers the widget in YouTrack in the HTML code of the widget.
Here you can see an example of the registration script:
When you've registered the widget, you can use the Host API to send alerts in YouTrack or invoke functions implemented as custom HTTP handlers.
Host API Reference
Here is the list of methods that the Host API supports.
alert
This method allows you to send an alert message to YouTrack from within an app.
Parameter | Type | Description | Required |
---|---|---|---|
message | String | The text of the alert message. | ✓ |
Here you can find a sample code that uses this method:
fetchYouTrack
This method lets the app use the YouTrack REST API.
Parameter | Type | Description | Required |
---|---|---|---|
relativeURL | String | The relative URL to the REST API endpoint. | ✓ |
requestParams | RequestParams | Optional fetch parameters. For additional information, see requestParams below. |
|
Here you can find a sample code that uses this method:
Here's a sample that contains optional query parameters:
fetchApp
This method lets the app communicate with the custom HTTP handler and invoke its methods. The fetchApp
method is similar to the fetchYouTrack
method, but has an additional scope
parameter. This parameter lets you indicate whether the request should be made to a scoped or global endpoint.
The fetchApp
method parses JSON and returns a ready-to-use response object.
Parameter | Type | Description | Required |
---|---|---|---|
relativeURL | String | The relative URL to the custom HTTP endpoint. For more details, see HTTP Handlers. | ✓ |
requestParams | RequestParams & {scope: boolean} | Optional fetch parameters. For details, see requestParams below. You have the option to set the scope for the handler in this parameter. Pass an empty object to set the scope to When the HTTP handler you're trying to access has limited scope, set the scope to |
|
Here you can find a sample code that uses this method:
Here's a sample GET request with query parameters:
Here's a sample POST request with body:
requestParams
The requestParams
object is basically an extension of the requestInit object used to customize requests in the Fetch API. In addition to the base properties supported by the requestInit
object, requestParams
supports the following supplemental properties:
Property | Description |
---|---|
query | A JavaScript object that contains key-value pairs that are used as query parameters for the HTTP request. For example:
const query = {
key: '12345',
shelterID: 'abc00',
count: 20,
animals: true
};
|
scope | A Boolean property that indicates if the request should be made to a scoped or global endpoint. For example:
// appResponse is a parsed JSON:
const appResponse = await host.fetchApp('backend/demo', {scope: true});
console.log('test', appResponse.test);
|
Custom Widget API Reference
Apps that use the DASHBOARD_WIDGET and MARKDOWN extension points generate a special embedding component each time its widgets are inserted into a dashboard or text field. This component stores the data the widget displays in these locations. As a result, these widgets are supported by a more extensive API that we call the CustomWidgetAPILayer
.
Here is the list of additional methods that are supported for these extension points.
setTitle
Sets the text displayed in the widget header. If a value is specified for the labelUrl
parameter, the text is set as a link to the target URL.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
label | String | The string that is shown as the widget title. | ✓ |
labelURL | String | The address of the target page that opens when a user clicks the widget title. If this optional parameter is not specified, the widget title is set as text only. |
|
setLoadingAnimationEnabled
Toggles the image rotation animation for the widget reload icon. Call this method when the widget populates data from a remote server to indicate that a process is running in the background.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
isEnabled | Boolean | Determines whether the widget reload icon rotates or not. | ✓ |
enterConfigMode
Invokes configuration mode. When in configuration mode, the visual presentation of the widget changes to indicate that its settings can be updated. The refresh icon is also hidden.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
exitConfigMode
Exits configuration mode.
setError
Sets an error state in the widget, displaying an error message or taking other error-handling actions.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
e | Error | The error object containing details about the error. | ✓ |
clearError
Clears any previously set error state in the widget.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
readCache
Reads data previously stored in the cache. Returns a promise that resolves to the cached data.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
storeCache
Stores any object in the client-side cache. Use this method to store populated data locally and display it immediately in the widget, then refresh it from the server. Returns a promise that resolves when the data is successfully stored.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
data | Unknown | Specifies the data to be stored in the cache. | ✓ |
readConfig
Reads the widget configuration data. Returns a promise that resolves to the configuration data.
The schema for the config object must be declared in the settingsSchemaPath
property of the widget manifest. Any undeclared payloads are ignored.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
storeConfig
Stores configuration data for the widget. Exits configuration mode if configuration mode is active.
The schema for the config object must be declared in the settingsSchemaPath
property of the widget manifest. Any undeclared payloads are ignored.
Returns a promise that resolves when the configuration data is successfully stored.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
config | Unknown | The configuration data to be stored. | ✓ |
downloadFile
Downloads a file from a specified service.
Returns a promise that resolves when the file is successfully downloaded.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
serviceID | String | The ID of the service from which the file will be downloaded. | ✓ |
relativeURL | String | The relative URL path to the file within the service. | ✓ |
requestParams | Unknown | Parameters to be included in the request. | ✓ |
fileName | String | The name of the file to be downloaded. If not specified, the service may provide a default name. |
|
fetchHub
Fetches data from the Hub service that is connected to or built into YouTrack. Similar to the fetch
method but specifically designed for Hub services.
Returns the fetched data. The return type depends on the information retrieved from the service.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
relativeURL | String | Sets the URL to the Hub service API endpoint. This is the path to the resource that you want to fetch. The URL is relative to the server home URL. For more information, refer to the Hub documentation. | ✓ |
requestParams | RequestParams | Optional parameters that you want to include in the request. |
|
For example:
The following example shows how to use this method in a POST request:
alert
Displays a system alert in the lower left corner of the page.
This is a wrapper for the AlertService component from the JetBrains Ring UI component library.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.
Parameter | Type | Description | Required |
---|---|---|---|
args | Parameters | The parameters required by the | ✓ |
For example:
removeWidget
Removes the embedded widget from the user interface.
Only available for widgets that use the DASHBOARD_WIDGET
pr MARKDOWN
extension points.