GlideHTTPResponse - グローバル
GlideHTTPResponse API は、Glide HTTP 応答で一般的な機能を実行するためのユーティリティメソッドを提供します。
GlideHTTPResponse - getAllHeaders()
すべてのヘッダーのリストを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| アレイ | エンドポイント呼び出しに関連付けられているすべてのヘッダーのリスト。 |
この例は、del() メソッドを使用してインシデントテーブルから指定されたインシデントを削除する方法を示しています。
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 all headers associated with the endpoint call
gs.print(response.getAllHeaders());
出力
[
X-Is-Logged-In: true,
X-Transaction-ID: 21a9223f1b13,
X-Total-Count: 69,
X-Content-Type-Options: nosniff,
Pragma: no-store,no-cache,
Cache-Control: no-cache,no-store,must-revalidate,
max-age=-1,
Expires: 0,
Content-Type: application/json;charset=UTF-8,
Transfer-Encoding: chunked,
Date: Tue, 26 Oct 2021 16:54:24 GMT,
Server: ServiceNow,
Set-Cookie: JSESSIONID=36B9B3E86C31E244A50AF38106376F9B; Path=/; HttpOnly; SameSite=None; Secure,
Set-Cookie: glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,
Set-Cookie: glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,
Set-Cookie: glide_user_route=glide.455981d2bb48a9658f44c18e5f56313d; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 20:08:31 GMT; Path=/; HttpOnly; SameSite=None; Secure,
Set-Cookie: glide_session_store=E9A9223F1B1370107CF30D03CD4BCB8D; Max-Age=1800; Expires=Tue, 26-Oct-2021 17:24:24 GMT; Path=/; HttpOnly; SameSite=None; Secure,
Set-Cookie: BIGipServerpool_jsmith=428037898.31808.0000; path=/; Httponly; Secure; SameSite=None; Secure, Strict-Transport-Security: max-age=63072000; includeSubDomains
]
GlideHTTPResponse - getBody()
HTTP 応答の本文を含む文字列を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | HTTP 応答本文。 |
この例は、getBody() メソッドを使用して、エンドポイント呼び出しで返される結果の内容を表示する方法を示しています。
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');
request.addHeader('Content-Type','application/json');
var response = request.post('{"short_description":"Test me"}');
gs.print(response.getStatusCode());
gs.print(response.getBody());
出力
201
{
"result":{
"parent":"",
"made_sla":"true",
"caused_by":"",
"watch_list":"",
"upon_reject":"cancel",
"sys_updated_on":"2021-10-26 14:59:22",
"child_incidents":"0",
"hold_reason":"",
"task_effective_number":"INC0010003",
"approval_history":"",
"skills":"",
"number":"INC0010003",
"resolved_by":"",
"sys_updated_by":"admin",
"opened_by":{
"link":"https://instanceName.servicenow.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value":"6816f79cc0a8016401c5a33be04be441"
},
"user_input":"",
"sys_created_on":"2021-10-26 14:59:22",
"sys_domain":{
"link":"https://instanceName.servicenow.com/api/now/table/sys_user_group/global",
"value":"global"
},
"state":"1",
"route_reason":"",
"sys_created_by":"admin",
"knowledge":"false",
"order":"",
"calendar_stc":"",
"closed_at":"",
"cmdb_ci":"",
"delivery_plan":"",
"contract":"",
"impact":"3",
"active":"true",
"work_notes_list":"",
"business_service":"",
"priority":"5",
"sys_domain_path":"/",
"rfc":"",
"time_worked":"",
"expected_start":"",
"opened_at":"2021-10-26 14:59:22",
"business_duration":"",
"group_list":"",
"work_end":"",
"caller_id":"",
"reopened_time":"",
"resolved_at":"",
"approval_set":"",
"subcategory":"",
"work_notes":"",
"universal_request":"",
"short_description":"Test me",
"close_code":"",
"correlation_display":"",
"delivery_task":"",
"work_start":"",
"assignment_group":"",
"additional_assignee_list":"",
"business_stc":"",
"description":"",
"calendar_duration":"",
"close_notes":"",
"notify":"1",
"service_offering":"",
"sys_class_name":"incident",
"closed_by":"",
"follow_up":"",
"parent_incident":"",
"sys_id":"a85f82ffdb5f30103dd9c39d13961916",
"contact_type":"",
"reopened_by":"",
"incident_state":"1",
"urgency":"3",
"problem_id":"",
"company":"",
"reassignment_count":"0",
"activity_due":"",
"assigned_to":"",
"severity":"3",
"comments":"",
"approval":"not requested",
"sla_due":"",
"comments_and_work_notes":"",
"due_date":"",
"sys_mod_count":"0",
"reopen_count":"0",
"sys_tags":"",
"escalation":"0",
"upon_approval":"proceed",
"correlation_id":"",
"location":"",
"category":"inquiry"
}
}
GlideHTTPResponse - getCookies()
エンドポイント呼び出しに関連付けられた cookie のリストを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| アレイ | 各 cookie の名前と値を文字列として含むリスト。 |
この例では、getCookies() メソッドを使用してエンドポイント応答に関連付けられた cookie を表示する方法を示します。
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(response.getCookies());
出力
200
[
JSESSIONID=B8E5C1C0E43FEA35EC0FCB323A9DF8D1;
Path=/; HttpOnly; SameSite=None; Secure, glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;
Path=/; HttpOnly; SameSite=None; Secure, glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;
Path=/; HttpOnly; SameSite=None; Secure, glide_user_route=glide.f1aa2015b3fa5fa8dfe567386cde8fd5; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 21:02:31 GMT;
Path=/; HttpOnly; SameSite=None; Secure, glide_session_store=7406BAB7DBDF30103DD9C39D13961966; Max-Age=1800; Expires=Tue, 26-Oct-2021 18:18:24 GMT;
Path=/; HttpOnly; SameSite=None; Secure, BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure
]
GlideHTTPResponse - getErrorCode()
エンドポイントによって返された現在のエラーコードを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 整数 | エラーコード。エラーがない場合は 0 が返されます。 |
この例は、getErrorCode() メソッドを使用して、関連する REST 呼び出しのインスタンスによってスローされた前回のエラーメッセージのエラーコードを表示する方法を示しています。
var instance = 'dev12345'; // Instance name
var username = 'admin';
var password = 'yourpassword';
var sysId = '0123456789abcdef0123456789abcdef'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Delete the incident
response = request.get();
// Print the results: status code and response body
gs.print(response.getStatusCode());
// Get the last error message
gs.print(response.getErrorCode());
出力
404
1
GlideHTTPResponse - getErrorMessage()
前回発生したエラーを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 前回発生したエラーを説明するテキスト文字列。 |
この例は、getErrorMessage() メソッドを使用して、関連する REST 呼び出しのインスタンスによってスローされた前回のエラーメッセージを表示する方法を示しています。
var instance = 'dev12345'; // Instance name
var username = 'admin';
var password = 'yourpassword';
var sysId = '0123456789abcdef0123456789abcdef'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Try to get the non-existent incident
response = request.get();
// Print the results: status code and response body
gs.print(response.getStatusCode());
// Get the last error message
gs.print(response.getErrorMessage());
出力
404
Method failed: (/api/now/table/incident/0123456789abcdef0123456789abcdef) with code: 404
GlideHTTPResponse - getHeader(文字列 name)
渡されたパラメーターで指定されたヘッダーを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| name | 文字列 | Content-Type など、返される応答ヘッダーの名前。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 現在の応答の指定されたヘッダーの値。 |
この例は、Content-Type ヘッダーの内容を表示する方法を示しています。
var instance = 'dev12345'; // Instance name
var username = 'admin';
var password = 'yourpassword';
var sysId = '0123456789abcdef0123456789abcdef'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Execute the GET request
var response = request.get();
// Print the results
gs.print(response.getStatusCode());
gs.print(response.getHeader("Content-Type"));
出力
200
application/json
GlideHTTPResponse - getHeaders()
エンドポイント応答に関連付けられたすべてのヘッダーを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | 関連するすべてのヘッダーを含むオブジェクト。 |
この例は、getHeaders() メソッドを使用して、エンドポイント呼び出しに関連付けられたすべてのヘッダーを表示する方法を示しています。
var instance = 'dev12345'; // Instance name
var username = 'admin';
var password = 'yourpassword';
var sysId = '0123456789abcdef0123456789abcdef'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Execute the GET request
var response = request.get();
// Print the results
gs.print(response.getStatusCode());
gs.print(response.getHeaders());
出力
200
{
Transfer-Encoding=chunked,
Strict-Transport-Security=max-age=63072000; includeSubDomains,
Cache-Control=no-cache, no-store, must-revalidate,
max-age=-1,
Server=ServiceNow,
X-Content-Type-Options=nosniff,
X-Transaction-ID=399f8f73db13,
X-Is-Logged-In=true,
Set-Cookie=BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure,
Pragma=no-store,no-cache, Expires=0, Date=Tue, 26 Oct 2021 19:40:10 GMT,
Content-Type=application/json;charset=UTF-8
}
GlideHTTPResponse - getHttpMethod()
指定されたエンドポイント呼び出しに関連付けられた HTTP メソッドを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | エンドポイント呼び出しに関連付けられた HTTP メソッド (org.apache.commons.httpclient.methods.GetMethod@f83e63 など)。 形式:org.apache.commons.httpclient.methods.<メソッド> |
この例は、getMethod() メソッドを使用して関連するエンドポイントを呼び出すときに使用される HTTP メソッドを表示する方法を示しています。
var instance = 'dev12345'; // Instance name
var username = 'admin';
var password = 'yourpassword';
var sysId = '0123456789abcdef0123456789abcdef'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Execute the GET request
var response = request.get();
// Print the results
gs.print(response.getStatusCode());
gs.print(response.getHttpMethod());
出力
200
org.apache.commons.httpclient.methods.GetMethod@f83e63
GlideHTTPResponse - getStatusCode()
エンドポイント呼び出しの前回のステータスコードを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| int | HTTP 応答ステータスコード。 |
この例は、REST 呼び出しが getStatusCode() メソッドを使用して実行された後に、そのステータスコードを取得する方法を示しています。
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
gs.print(response.getStatusCode());
出力:
200
GlideHTTPResponse - haveError()
エンドポイント呼び出しの処理中にエラーが発生したかどうかを示すフラグを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | エンドポイント呼び出しの処理中にエラーが発生したかどうかを示すフラグ。 有効な値: エラーが発生した場合は true を返し、エラーがない場合は false を返します。
|
この例は、haveError() メソッドを使用して、インシデントの sys_id が有効である場合にエラーなしのフラグを付ける方法を示しています。
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Valid sys_id of an incident record
var sysId = 'a85f82ffdb5f30103dd9c39d13961916'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Execute the GET request
var response = request.get();
// Print the results
gs.print(response.getStatusCode());
gs.print(response.haveError());
出力
200
false
この例は、haveError() メソッドを使用して、インシデントの sys_id が有効でない場合にエラーのフラグを付ける方法を示しています。
var instance = 'dev12345';
var username = 'admin';
var password = 'yourpassword';
// Invalid sys_id
var sysId = 'a85f82ffdb5f30103dd9c39d13961832'; // Sys_id of the incident to get
// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident
var endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;
var request = new GlideHTTPRequest(endpoint);
// Add authentication data
request.setBasicAuth(username, password);
// Execute the GET request
var response = request.get();
// Print the results
gs.print(response.getStatusCode());
gs.print(response.haveError());
出力
404
true