Do GraphQL call from ServiceNow
Tue Feb 13 2024 06:15:33 GMT+0000 (Coordinated Universal Time)
Saved by
@RahmanM
// var instance = 'dev12345';
// var username = 'admin';
// var password = 'yourpassword';
var graphql = JSON.stringify({
query: "query {\r\n countries {\r\n name\r\n }\r\n}",
variables: {}
})
// Instantiate request with ServiceNow API incidents table endpoint
var request = new GlideHTTPRequest('https://countries.trevorblades.com/');
// 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.post(graphql);
// Print the results: status code and number of records returned
gs.print(response.getStatusCode());
gs.print('Countries Response: ' + response.getBody());
content_copyCOPY
Comments