{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":798,"path":"api-reference/server-api-reference/GlideHTTPResponseAPI.md","title":"GlideHTTPResponse - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideHTTPResponse- Global\n\nThe GlideHTTPResponse API provides utility methods to perform common functions with Glide HTTP responses.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideHTTPResponse - getAllHeaders\\(\\)\n\nReturns a list of all headers.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|List of all the headers associated with the endpoint call.|\n\nThis example shows how to delete a specified incident from the Incident table using the del\\(\\) method.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Instantiate request with ServiceNow API incidents table endpoint\nvar request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Add the Accept header to get JSON response\nrequest.addHeader('Accept', 'application/json');\n\n// Execute the GET request\nvar response = request.get();\n\n// Print all headers associated with the endpoint call\ngs.print(response.getAllHeaders());\n```\n\nOutput\n\n```\n[\n  X-Is-Logged-In: true, \n  X-Transaction-ID: 21a9223f1b13, \n  X-Total-Count: 69,\n  X-Content-Type-Options: nosniff,\n  Pragma: no-store,no-cache,\n  Cache-Control: no-cache,no-store,must-revalidate,\n  max-age=-1,\n  Expires: 0,\n  Content-Type: application/json;charset=UTF-8,\n  Transfer-Encoding: chunked,\n  Date: Tue, 26 Oct 2021 16:54:24 GMT,\n  Server: ServiceNow,\n  Set-Cookie: JSESSIONID=36B9B3E86C31E244A50AF38106376F9B; Path=/; HttpOnly; SameSite=None; Secure,\n  Set-Cookie: glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,\n  Set-Cookie: glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure,\n  Set-Cookie: glide_user_route=glide.455981d2bb48a9658f44c18e5f56313d; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 20:08:31 GMT; Path=/; HttpOnly; SameSite=None; Secure,\n  Set-Cookie: glide_session_store=E9A9223F1B1370107CF30D03CD4BCB8D; Max-Age=1800; Expires=Tue, 26-Oct-2021 17:24:24 GMT; Path=/; HttpOnly; SameSite=None; Secure,\n  Set-Cookie: BIGipServerpool_jsmith=428037898.31808.0000; path=/; Httponly; Secure; SameSite=None; Secure, Strict-Transport-Security: max-age=63072000; includeSubDomains\n]\n\n```\n\n## GlideHTTPResponse - getBody\\(\\)\n\nReturns a string containing the body for the HTTP response.\n\n**Note:** If the stream has already been accessed, it cannot be accessed again. In this case the method will return null.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|HTTP response body.|\n\nThis example shows how to use the getBody\\(\\) method to display the contents of the return results of an endpoint call.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Instantiate request with ServiceNow API incidents table endpoint\nvar request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Add the Accept header to get JSON response\nrequest.addHeader('Accept', 'application/json');\nrequest.addHeader('Content-Type','application/json');\n \nvar response = request.post('{\"short_description\":\"Test me\"}');\n \ngs.print(response.getStatusCode());\ngs.print(response.getBody());\n```\n\nOutput\n\n```\n201\n{\n  \"result\":{\n    \"parent\":\"\",\n    \"made_sla\":\"true\",\n    \"caused_by\":\"\",\n    \"watch_list\":\"\",\n    \"upon_reject\":\"cancel\",\n    \"sys_updated_on\":\"2021-10-26 14:59:22\",\n    \"child_incidents\":\"0\",\n    \"hold_reason\":\"\",\n    \"task_effective_number\":\"INC0010003\",\n    \"approval_history\":\"\",\n    \"skills\":\"\",\n    \"number\":\"INC0010003\",\n    \"resolved_by\":\"\",\n    \"sys_updated_by\":\"admin\",\n    \"opened_by\":{\n      \"link\":\"https://instanceName.servicenow.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441\",\n      \"value\":\"6816f79cc0a8016401c5a33be04be441\"\n    },\n    \"user_input\":\"\",\n    \"sys_created_on\":\"2021-10-26 14:59:22\",\n    \"sys_domain\":{\n      \"link\":\"https://instanceName.servicenow.com/api/now/table/sys_user_group/global\",\n      \"value\":\"global\"\n    },\n    \"state\":\"1\",\n    \"route_reason\":\"\",\n    \"sys_created_by\":\"admin\",\n    \"knowledge\":\"false\",\n    \"order\":\"\",\n    \"calendar_stc\":\"\",\n    \"closed_at\":\"\",\n    \"cmdb_ci\":\"\",\n    \"delivery_plan\":\"\",\n    \"contract\":\"\",\n    \"impact\":\"3\",\n    \"active\":\"true\",\n    \"work_notes_list\":\"\",\n    \"business_service\":\"\",\n    \"priority\":\"5\",\n    \"sys_domain_path\":\"/\",\n    \"rfc\":\"\",\n    \"time_worked\":\"\",\n    \"expected_start\":\"\",\n    \"opened_at\":\"2021-10-26 14:59:22\",\n    \"business_duration\":\"\",\n    \"group_list\":\"\",\n    \"work_end\":\"\",\n    \"caller_id\":\"\",\n    \"reopened_time\":\"\",\n    \"resolved_at\":\"\",\n    \"approval_set\":\"\",\n    \"subcategory\":\"\",\n    \"work_notes\":\"\",\n    \"universal_request\":\"\",\n    \"short_description\":\"Test me\",\n    \"close_code\":\"\",\n    \"correlation_display\":\"\",\n    \"delivery_task\":\"\",\n    \"work_start\":\"\",\n    \"assignment_group\":\"\",\n    \"additional_assignee_list\":\"\",\n    \"business_stc\":\"\",\n    \"description\":\"\",\n    \"calendar_duration\":\"\",\n    \"close_notes\":\"\",\n    \"notify\":\"1\",\n    \"service_offering\":\"\",\n    \"sys_class_name\":\"incident\",\n    \"closed_by\":\"\",\n    \"follow_up\":\"\",\n    \"parent_incident\":\"\",\n    \"sys_id\":\"a85f82ffdb5f30103dd9c39d13961916\",\n    \"contact_type\":\"\",\n    \"reopened_by\":\"\",\n    \"incident_state\":\"1\",\n    \"urgency\":\"3\",\n    \"problem_id\":\"\",\n    \"company\":\"\",\n    \"reassignment_count\":\"0\",\n    \"activity_due\":\"\",\n    \"assigned_to\":\"\",\n    \"severity\":\"3\",\n    \"comments\":\"\",\n    \"approval\":\"not requested\",\n    \"sla_due\":\"\",\n    \"comments_and_work_notes\":\"\",\n    \"due_date\":\"\",\n    \"sys_mod_count\":\"0\",\n    \"reopen_count\":\"0\",\n    \"sys_tags\":\"\",\n    \"escalation\":\"0\",\n    \"upon_approval\":\"proceed\",\n    \"correlation_id\":\"\",\n    \"location\":\"\",\n    \"category\":\"inquiry\"\n  }\n}\n```\n\n## GlideHTTPResponse - getCookies\\(\\)\n\nReturns the list of cookies associated with an endpoint call.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|List containing the name and value of each cookie as a string.|\n\nThis example shows how to use the getCookies\\(\\) method to display the cookies associated with a endpoint response.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Instantiate request with ServiceNow API incidents table endpoint\nvar request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Add the Accept header to get JSON response\nrequest.addHeader('Accept', 'application/json');\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results: status code and number of records returned\ngs.print(response.getStatusCode());\ngs.print(response.getCookies());\n```\n\nOutput\n\n```\n200\n[\n  JSESSIONID=B8E5C1C0E43FEA35EC0FCB323A9DF8D1; \n  Path=/; HttpOnly; SameSite=None; Secure, glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;\n  Path=/; HttpOnly; SameSite=None; Secure, glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT;\n  Path=/; HttpOnly; SameSite=None; Secure, glide_user_route=glide.f1aa2015b3fa5fa8dfe567386cde8fd5; Max-Age=2147483647; Expires=Sun, 13-Nov-2089 21:02:31 GMT;\n  Path=/; HttpOnly; SameSite=None; Secure, glide_session_store=7406BAB7DBDF30103DD9C39D13961966; Max-Age=1800; Expires=Tue, 26-Oct-2021 18:18:24 GMT;\n  Path=/; HttpOnly; SameSite=None; Secure, BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure\n]\n```\n\n## GlideHTTPResponse - getErrorCode\\(\\)\n\nReturns the current error code returned by an endpoint.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Integer|The error code. 0 is returned if there are no errors.|\n\nThis example shows how to view the error code of the last error message thrown by the instance for the associated REST call using the getErrorCode\\(\\) method.\n\n```\nvar instance = 'dev12345'; // Instance name\nvar username = 'admin';\nvar password = 'yourpassword';\nvar sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Delete the incident\nresponse = request.get();\n\n// Print the results: status code and response body\ngs.print(response.getStatusCode());\n\n// Get the last error message\ngs.print(response.getErrorCode());\n```\n\nOutput\n\n```\n404\n1\n```\n\n## GlideHTTPResponse - getErrorMessage\\(\\)\n\nReturns the last error encountered.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Text string that describes the last error encountered.|\n\nThis example shows how to view the last error message thrown by the instance for the associated REST call using the getErrorMessage\\(\\) method.\n\n```\nvar instance = 'dev12345'; // Instance name\nvar username = 'admin';\nvar password = 'yourpassword';\nvar sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Try to get the non-existent incident\nresponse = request.get();\n\n// Print the results: status code and response body\ngs.print(response.getStatusCode());\n\n// Get the last error message\ngs.print(response.getErrorMessage());\n```\n\nOutput\n\n```\n404\nMethod failed: (/api/now/table/incident/0123456789abcdef0123456789abcdef) with code: 404\n```\n\n## GlideHTTPResponse - getHeader\\(String name\\)\n\nReturns the header specified in the passed-in parameter.\n\n|Name|Type|Description|\n|----|----|-----------|\n|name|String|Name of the response header to return, such as **Content-Type**.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the specified header for the current response.|\n\nThis example shows how to display the contents of the **Content-Type** header.\n\n```\nvar instance = 'dev12345'; // Instance name\nvar username = 'admin';\nvar password = 'yourpassword';\nvar sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results\ngs.print(response.getStatusCode());\ngs.print(response.getHeader(\"Content-Type\"));\n```\n\nOutput\n\n```\n200\napplication/json\n```\n\n## GlideHTTPResponse - getHeaders\\(\\)\n\nReturns all headers associated with the endpoint response.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|Object containing all associated headers.|\n\nThis example shows how to display all of the headers associated with an endpoint call using the getHeaders\\(\\) method.\n\n```\nvar instance = 'dev12345'; // Instance name\nvar username = 'admin';\nvar password = 'yourpassword';\nvar sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results\ngs.print(response.getStatusCode());\ngs.print(response.getHeaders());\n```\n\nOutput\n\n```\n200\n{\n  Transfer-Encoding=chunked, \n  Strict-Transport-Security=max-age=63072000; includeSubDomains,\n  Cache-Control=no-cache, no-store, must-revalidate,\n  max-age=-1,\n  Server=ServiceNow,\n  X-Content-Type-Options=nosniff,\n  X-Transaction-ID=399f8f73db13,\n  X-Is-Logged-In=true,\n  Set-Cookie=BIGipServerpool_jsmith=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure,\n  Pragma=no-store,no-cache, Expires=0, Date=Tue, 26 Oct 2021 19:40:10 GMT, \n  Content-Type=application/json;charset=UTF-8\n}\n\n```\n\n## GlideHTTPResponse - getHttpMethod\\(\\)\n\nReturns the HTTP method associated with the specified endpoint call.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nHTTP method associated with the endpoint call, such as `org.apache.commons.httpclient.methods.GetMethod@f83e63`. Format: org.apache.commons.httpclient.methods.&lt;Method&gt;\n\n</td></tr></tbody>\n</table>This example shows how to display the HTTP method used when calling the associated endpoint using the getMethod\\(\\) method.\n\n```\nvar instance = 'dev12345'; // Instance name\nvar username = 'admin';\nvar password = 'yourpassword';\nvar sysId = '0123456789abcdef0123456789abcdef';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results\ngs.print(response.getStatusCode());\ngs.print(response.getHttpMethod());\n```\n\nOutput\n\n```\n200\norg.apache.commons.httpclient.methods.GetMethod@f83e63\n```\n\n## GlideHTTPResponse - getStatusCode\\(\\)\n\nReturns the last status code for an endpoint call.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|int|HTTP response status code.|\n\nThis example shows how to get the status code of a REST call after it executes using the getStatusCode\\(\\) method.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Instantiate request with ServiceNow API incidents table endpoint\nvar request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Add the 'sysparm_limit' parameter to limit the number of records returned\nrequest.addParameter('sysparm_limit', 1);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results: status code\ngs.print(response.getStatusCode());\n```\n\nOutput:\n\n```\n200\n```\n\n## GlideHTTPResponse - haveError\\(\\)\n\nReturns a flag that indicates whether there were any errors while processing the endpoint call.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_zpm_g52_dfb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether there were any errors when processing the endpoint call.Valid values:\n\n-   true: Error occurred during the processing of the endpoint.\n-   false: No errors during the processing of the endpoint.\n\nReturns true if an error has occurred, or false if there are no errors\n\n</td></tr></tbody>\n</table>This example shows how no error is flagged when the sys\\_id for an incident is valid using the haveError\\(\\) method.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Valid sys_id of an incident record\nvar sysId = 'a85f82ffdb5f30103dd9c39d13961916';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results\ngs.print(response.getStatusCode());\ngs.print(response.haveError());\n```\n\nOutput\n\n```\n200\nfalse\n```\n\nThis example shows how an error is flagged when the sys\\_id for an incident is not valid \\(not found\\) using the haveError\\(\\) method.\n\n```\nvar instance = 'dev12345';\nvar username = 'admin';\nvar password = 'yourpassword';\n\n// Invalid sys_id\nvar sysId = 'a85f82ffdb5f30103dd9c39d13961832';  // Sys_id of the incident to get\n\n// Instantiate request with the ServiceNow API incident table endpoint for deletion of an incident\nvar endpoint = 'https://' + instance + '.service-now.com/api/now/table/incident/' + sysId;\nvar request = new GlideHTTPRequest(endpoint);\n\n// Add authentication data\nrequest.setBasicAuth(username, password);\n\n// Execute the GET request\nvar response = request.get();\n\n// Print the results\ngs.print(response.getStatusCode());\ngs.print(response.haveError());\n```\n\nOutput\n\n```\n404\ntrue\n```\n\n"}}