YouTrack および Hub ヘルプの開発者ポータル

Response

HTTP レスポンスの定義を作成するクラス処理中に例外が発生した場合、応答オブジェクト内のほとんどのプロパティは空です。

// Gets the content of a PasteBin paste, assuming that we have received its key (`pasteBinKey`) in a prior request. const http = require('@jetbrains/youtrack-scripting-api/http'); 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

名前

タイプ

説明

文字列

読み取り専用。レスポンスボディ。response プロパティと同じ値が含まれます。リクエストの処理中に例外が発生した場合は、値は null になります。

2024.2 から利用可能

bodyAsStream

オブジェクト

読み取り専用。レスポンスボディのバイトストリーム表現。responseAsStream プロパティと同じ値が含まれます。リクエストの処理中に例外が発生した場合、値は null になります。

2024.2 から利用可能

コード

応答に割り当てられた HTTP ステータスコード。処理中に例外が発生した場合、プロパティは空です。

例外

オブジェクト

処理中に発生した例外。

ヘッダー

Array。<{ 名前: 文字列、値: 文字列 }>

応答ヘッダーのコレクション。処理中に例外が発生した場合、コレクションは空です。

成功

boolean

リクエストの成功または失敗を示す値。HTTP ステータスコードが 200 (含む) から 400 (含まない) の間である場合、このプロパティは true に設定されます。

応答

文字列

レスポンス本文。処理中に例外が発生した場合、レスポンス本文は空になります (null)。

レスポンスストリーム

オブジェクト

レスポンス本文のバイトストリーム表現。処理中に例外が発生した場合、プロパティは空になります (null)。

メソッド

json

json()

レスポンスボディを JSON として解析します。これは JSON レスポンスを読み取る推奨方法です。ボディが文字列の場合、JSON.parse(response.response) と同等です。ボディがすでにオブジェクトに解析されている場合、このメソッドはそれを変更せずに返します。JSON.parse と同様に、ボディに有効な JSON が含まれていない場合、このメソッドは例外をスローします。ボディを解析する前に、isSuccess または code の値を確認してください。

2024.2 から利用可能

戻り値

タイプ

説明

オブジェクト、配列

解析されたレスポンスボディ。

サンプル
// Reads a JSON response from a third-party service. // The API key is stored in the app settings as a secret, so it is passed to the `addHeader` method as is. // Concatenating the API key with a string produces a string that contains a mask instead of the API key. const http = require('@jetbrains/youtrack-scripting-api/http'); const connection = new http.Connection('https://api.example.com'); connection.addHeader('X-Api-Key', ctx.settings.apiKey); const response = connection.getSync('customers/' + customerId); if (response.isSuccess) { const customer = response.json(); ctx.issue.addComment('Customer plan: ' + customer.plan); } else { console.warn('Request failed: ' + response.code + ' ' + response.response); }
2026 年 9 月 10 日