---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideHTTPRequest - グローバル

# GlideHTTPRequest - グローバル {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：13分

GlideHTTPRequest API は、Glide HTTP 要求で一般的な機能を実行するためのユーティリティメソッドを提供します。

この API は、グローバルサーバーサイドスクリプトで使用できます。このクラスを使用するには、コンストラクターを使用して GlideHTTPRequest オブジェクトをインスタンス化します。コンストラクターには、入力パラメーターとしてエンドポイント URL が必要です。

## GlideHTTPRequest - addHeader(文字列 name, 文字列 value) {#ariaid-title2}

HTTP 要求にヘッダーを追加します。
{#GlideHTTPRequest-addHeader__table_ib1_31z_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| name | 文字列 | `Accept` や `Content-Type` などのヘッダー名。 |
| value | 文字列 | `application/json` などのヘッダー値。 |
[表 : 1. パラメーター]

{#GlideHTTPRequest-addHeader__table_ib1_31z_cfb} {#GlideHTTPRequest-addHeader__table_jb1_31z_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 2. 返される内容]

{#GlideHTTPRequest-addHeader__table_jb1_31z_cfb}  
この例では、要求ヘッダー「Accept」を追加し、JSON または XML 応答を解析して、ServiceNow インスタンスからインシデントの数を返します。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);

    // Replace the Accept header to get XML response
    request.addHeader('Accept', 'application/xml');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);

出力

    200
    (JSON) Incidents returned: 66
    200
    (XML) Incidents returned: 66

## GlideHTTPRequest - addParameter(文字列 name, 文字列 value) {#ariaid-title3}

HTTP 要求にパラメーターを追加します。
{#GlideHTTPRequest-addParameter__table_zk5_4dz_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| name | 文字列 | sysparm_limit などの追加するパラメーター。 |
| value | 文字列 | パラメーターの値。 |
[表 : 3. パラメーター]

{#GlideHTTPRequest-addParameter__table_zk5_4dz_cfb} {#GlideHTTPRequest-addParameter__entry__11}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 4. 返される内容]

この例では、REST エンドポイント呼び出しに sysparm_limit パラメーターを追加して、返される応答の数を制限する方法を示します。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the 'sysparm_limit' parameter to limit the number of records returned
    request.addParameter('sysparm_limit', 1);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('Incidents returned: ' + JSON.parse(response.getBody()).result.length);

出力:

    200
    Incidents returned: 1

## GlideHTTPRequest - setBasicAuth(文字列 userName, 文字列 password) {#ariaid-title4}

基本認証のユーザー名とパスワードを設定します。
{#GlideHTTPRequest-setBasicAuth__table_xtx_5qy_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| userName | 文字列 | 認証に使用するユーザー名。 |
| password | 文字列 | 認証に使用するユーザーのパスワード。 |
[表 : 5. パラメーター]

{#GlideHTTPRequest-setBasicAuth__table_xtx_5qy_cfb} {#GlideHTTPRequest-setBasicAuth__table_ytx_5qy_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 6. 返される内容]

{#GlideHTTPRequest-setBasicAuth__table_ytx_5qy_cfb}  
この例では、setBasicAuth() メソッドを使用して、関連する REST エンドポイント呼び出しのユーザー名とパスワードを設定する方法を示します。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);

    // Replace the Accept header to get XML response
    request.addHeader('Accept', 'application/xml');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);

出力

    200
    (JSON) Incidents returned: 66
    200
    (XML) Incidents returned: 66

## GlideHTTPRequest - setContentType(文字列 type) {#ariaid-title5}

HTTP 要求のコンテンツタイプヘッダーを指定された値に設定します。
{#GlideHTTPRequest-setContentType__table_lhw_vdz_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| type | 文字列 | `application/json` や `multipart/form-data` など、設定するコンテンツタイプ。Content-Type の詳細については、「<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type>」を参照してください。 |
[表 : 7. パラメーター]

{#GlideHTTPRequest-setContentType__table_lhw_vdz_cfb} {#GlideHTTPRequest-setContentType__table_mhw_vdz_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 8. 返される内容]

{#GlideHTTPRequest-setContentType__table_mhw_vdz_cfb}  
この例は、setContentType() メソッドを使用して REST エンドポイント呼び出しの `Content-Type` 要求ヘッダーを設定する方法を示しています。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Set up incident record to post

    // Set the Content-Type of the POST
    request.setContentType('application/json');

    // Execute the POST request
    var response = request.post();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

出力

    200

## GlideHTTPRequest - setFollowRedirect(ブーリアン followRedirect) {#ariaid-title6}

REST エンドポイント呼び出しの followRedirect オプションを有効または無効にします。
HTTP リダイレクトの詳細については、「<https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections>」を参照してください。
{#GlideHTTPRequest-setFollowRedirect__table_kzt_pwy_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| followRedirect | ブーリアン | エンドポイントによって返された URL リダイレクトにエンドポイントが従う必要があるかどうかを示すフラグ。 有効な値： * true：返されたリダイレクトに従います。 * false：返されたリダイレクトを無視します。 デフォルト：true |
[表 : 9. パラメーター]

{#GlideHTTPRequest-setFollowRedirect__table_kzt_pwy_cfb} {#GlideHTTPRequest-setFollowRedirect__table_lzt_pwy_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 10. 返される内容]

{#GlideHTTPRequest-setFollowRedirect__table_lzt_pwy_cfb}  
この例は、setFollowRedirect() メソッドを使用してエンドポイント呼び出しのリダイレクトをオフにする方法を示しています。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Turn off follow redirect - default is on (true)
    request.setFollowRedirect(false);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

出力

    200

## GlideHTTPRequest - setHttpTimeout(int timeout) {#ariaid-title7}

HTTP タイムアウト値をミリ秒単位で設定します。
{#GlideHTTPRequest-setHttpTimeout__table_rjp_1ly_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| timeout | 整数 | 設定するタイムアウト値。 単位：ミリ秒 |
[表 : 11. パラメーター]

{#GlideHTTPRequest-setHttpTimeout__table_rjp_1ly_cfb} {#GlideHTTPRequest-setHttpTimeout__table_sjp_1ly_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 12. 返される内容]

{#GlideHTTPRequest-setHttpTimeout__table_sjp_1ly_cfb}  
この例では、setTimeout() メソッドを使用してエンドポイント呼び出しのタイムアウト値を設定する方法を示します。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Set the time out value
    request.setHttpTimeOut(1000);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

出力

    200

## GlideHTTPRequest - setLogLevel(文字列 logLevel) {#ariaid-title8}

HTTP 要求のログレベルを設定します。
{#GlideHTTPRequest-setLogLevel__table_ijx_myy_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| logLevel | 文字列 | 利用可能なログ記録のレベル。 注: パフォーマンス上の理由から、本番環境では HTTP 要求のログ記録を basic のままにすることをお勧めします。 有効な値： * basic：ホスト、パス、応答ステータスなど、HTTP トランザクションの多くの属性に対応します。 * elevated：basic のすべて、すべての要求ヘッダー、クエリ文字列、およびすべての応答ヘッダーが含まれます。 * all：elevated のすべて、および要求本文と応答本文が含まれます。 デフォルト：basic |
[表 : 13. パラメーター]

{#GlideHTTPRequest-setLogLevel__table_ijx_myy_cfb} {#GlideHTTPRequest-setLogLevel__table_jjx_myy_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 14. 返される内容]

{#GlideHTTPRequest-setLogLevel__table_jjx_myy_cfb}  
この例では、setLogLevel() メソッドを使用してエンドポイント呼び出しのログレベルを設定する方法を示します。

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Set the time out value
    request.setLogLevel(elevated);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

出力

    200

## GlideHTTPRequest - setupProxy(文字列 host, 文字列 port) {#ariaid-title9}

関連する REST 呼び出しのプロキシホストとポートを設定します。
{#GlideHTTPRequest-setupProxy__table_aww_sry_cfb__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| host | 文字列 | プロキシホスト |
| port | 文字列 | プロキシのポート |
[表 : 15. パラメーター]

{#GlideHTTPRequest-setupProxy__table_aww_sry_cfb} {#GlideHTTPRequest-setupProxy__table_bww_sry_cfb__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 16. 返される内容]

{#GlideHTTPRequest-setupProxy__table_bww_sry_cfb}

