---
sourceDocument: Referência de API do Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência de API do Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideHTTPResponse - Global

# GlideHTTPResponse - Global {#ariaid-title1}

* Versão de lançamento: Xanadu
* 
* Atualizado 1 de ago. de 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 8 min. de leitura

A API GlideHTTPResponse fornece métodos de utilitário para executar funções comuns com respostas HTTP do Glide.

## GlideHTTPResponse -- getAllHeaders() {#ariaid-title2}

Retorna uma lista de todos os cabeçalhos.
{#GlideHTTPResponse-getAllHeaders__table_azk_y32_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 1. Parâmetros]

{#GlideHTTPResponse-getAllHeaders__table_azk_y32_dfb} {#GlideHTTPResponse-getAllHeaders__table_bzk_y32_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Matriz | Lista de todos os cabeçalhos associados à chamada de endpoint. |
[Tabela 2. Retorna]

{#GlideHTTPResponse-getAllHeaders__table_bzk_y32_dfb}  
Este exemplo mostra como excluir um incidente especificado da tabela Incidente usando o método 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());

Saída

    [
      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() {#ariaid-title3}

Retorna uma cadeia de caracteres que contém o corpo da resposta HTTP.
Nota:  
Se o fluxo já tiver sido acessado, ele não poderá ser acessado novamente. Nesse caso, o método retornará nulo.
{#GlideHTTPResponse-getBody__table_mwd_gt2_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 3. Parâmetros]

{#GlideHTTPResponse-getBody__table_mwd_gt2_dfb} {#GlideHTTPResponse-getBody__table_nwd_gt2_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Corpo da resposta HTTP. |
[Tabela 4. Retorna]

{#GlideHTTPResponse-getBody__table_nwd_gt2_dfb}  
Este exemplo mostra como usar o método getBody() para exibir o conteúdo dos resultados de retorno de uma chamada de endpoint.

    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());

Saída

    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() {#ariaid-title4}

Retorna a lista de cookies associados a uma chamada de endpoint.
{#GlideHTTPResponse-getCookies__table_qmw_jj2_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 5. Parâmetros]

{#GlideHTTPResponse-getCookies__table_qmw_jj2_dfb} {#GlideHTTPResponse-getCookies__table_rmw_jj2_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Matriz | Lista que contém o nome e o valor de cada cookie como uma cadeia de caracteres. |
[Tabela 6. Retorna]

{#GlideHTTPResponse-getCookies__table_rmw_jj2_dfb}  
Este exemplo mostra como usar o método getCookies() para exibir os cookies associados a uma resposta de endpoint.

    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());

Saída

    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() {#ariaid-title5}

Retorna o código de erro atual retornado por um endpoint.
{#GlideHTTPResponse-getErrorCode__table_q4d_t52_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 7. Parâmetros]

{#GlideHTTPResponse-getErrorCode__table_q4d_t52_dfb} {#GlideHTTPResponse-getErrorCode__table_r4d_t52_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Inteiro | O código de erro. 0 será retornado se não houver erros. |
[Tabela 8. Retorna]

{#GlideHTTPResponse-getErrorCode__table_r4d_t52_dfb}  
Este exemplo mostra como exibir o código de erro da última mensagem de erro lançada pela instância para a chamada REST associada usando o método getErrorCode().

    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());

Saída

    404
    1

## GlideHTTPResponse -- getErrorMessage() {#ariaid-title6}

Retorna o último erro encontrado.
{#GlideHTTPResponse-getErrorMessage__table_llx_pxy_cfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 9. Parâmetros]

{#GlideHTTPResponse-getErrorMessage__table_llx_pxy_cfb} {#GlideHTTPResponse-getErrorMessage__table_mlx_pxy_cfb__entry__2}

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Cadeia de caracteres de texto que descreve o último erro encontrado. |
[Tabela 10. Retorna]

{#GlideHTTPResponse-getErrorMessage__table_mlx_pxy_cfb}  
Este exemplo mostra como exibir a última mensagem de erro lançada pela instância para a chamada REST associada usando o método getErrorMessage().

    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());

Saída

    404
    Method failed: (/api/now/table/incident/0123456789abcdef0123456789abcdef) with code: 404

## GlideHTTPResponse -- getHeader(String name) {#ariaid-title7}

Retorna o cabeçalho especificado no parâmetro passado.
{#GlideHTTPResponse-getHeader__table_rsl_c22_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| nome | Cadeia de caracteres | Nome do cabeçalho de resposta a ser retornado, como Content-Type. |
[Tabela 11. Parâmetros]

{#GlideHTTPResponse-getHeader__table_rsl_c22_dfb} {#GlideHTTPResponse-getHeader__table_ssl_c22_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Valor do cabeçalho especificado para a resposta atual. |
[Tabela 12. Retorna]

{#GlideHTTPResponse-getHeader__table_ssl_c22_dfb}  
Este exemplo mostra como exibir o conteúdo do cabeçalho 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"));

Saída

    200
    application/json

## GlideHTTPResponse -- getHeaders() {#ariaid-title8}

Retorna todos os cabeçalhos associados à resposta do endpoint.
{#GlideHTTPResponse-getHeaders__table_jyb_l32_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 13. Parâmetros]

{#GlideHTTPResponse-getHeaders__table_jyb_l32_dfb} {#GlideHTTPResponse-getHeaders__table_kyb_l32_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Objeto | Objeto que contém todos os cabeçalhos associados. |
[Tabela 14. Retorna]

{#GlideHTTPResponse-getHeaders__table_kyb_l32_dfb}  
Este exemplo mostra como exibir todos os cabeçalhos associados a uma chamada de endpoint usando o método 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());

Saída

    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() {#ariaid-title9}

Retorna o método HTTP associado à chamada de endpoint especificada.
{#GlideHTTPResponse-getHttpMethod__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 15. Parâmetros]

{#GlideHTTPResponse-getHttpMethod__entry__8}

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Método HTTP associado à chamada do endpoint, como `org.apache.commons.httpclient.methods.GetMethod@f83e63`. Formato: org.apache.commons.httpclient.methods.\<Method\> |
[Tabela 16. Retorna]

Este exemplo mostra como exibir o método HTTP usado ao chamar o endpoint associado usando o método getMethod().

    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());

Saída

    200
    org.apache.commons.httpclient.methods.GetMethod@f83e63

## GlideHTTPResponse -- getStatusCode() {#ariaid-title10}

Retorna o último código de status de uma chamada de endpoint.
{#GlideHTTPResponse-getStatusCode__table_cnd_fd2_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 17. Parâmetros]

{#GlideHTTPResponse-getStatusCode__table_cnd_fd2_dfb} {#GlideHTTPResponse-getStatusCode__table_dnd_fd2_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Número inteiro | Código de status de resposta HTTP. |
[Tabela 18. Retorna]

{#GlideHTTPResponse-getStatusCode__table_dnd_fd2_dfb}  
Este exemplo mostra como obter o código de status de uma chamada REST depois que ela é executada usando o método 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());

Saída:

    200

## GlideHTTPResponse -- haveError() {#ariaid-title11}

Retorna um sinalizador que indica se houve erros durante o processamento da chamada de endpoint.
{#GlideHTTPResponse-haveError__table_ypm_g52_dfb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 19. Parâmetros]

{#GlideHTTPResponse-haveError__table_ypm_g52_dfb} {#GlideHTTPResponse-haveError__table_zpm_g52_dfb__entry__2}

| Tipo | Descrição |
|-|-|
| Booliano | Sinalizador que indica se houve erros ao processar a chamada do endpoint. Valores válidos: * verdadeiro: ocorreu um erro durante o processamento do endpoint. * falso: não há erros durante o processamento do endpoint. Retorna verdadeiro se ocorreu um erro ou falso se não houver erros |
[Tabela 20. Retorna]

{#GlideHTTPResponse-haveError__table_zpm_g52_dfb}  
Este exemplo mostra como nenhum erro é sinalizado quando o sys_id de um incidente é válido usando o método haveError().

    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());

Saída

    200
    false

Este exemplo mostra como um erro é sinalizado quando o sys_id de um incidente não é válido (não encontrado) usando o método haveError().

    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());

Saída

    404
    true


