Table API server-side JavaScript examples

Examples that demonstrate how to use the Table API with the server-side JavaScript.

Example URLs

In the examples, replace myinstance.service-now.com with the URL of your instance.

GET

 var request = new GlideHTTPRequest
           ('https://myinstance.service-now.com/api/now/table/incident');
 request.setBasicAuth("admin","admin");
 request.addHeader('Accept','application/json');
 
 var response = request.get();
 
 gs.log(response.getStatusCode());
 gs.log(response.getBody());

POST

var request = new GlideHTTPRequest
           ('https://myinstance.service-now.com/api/now/table/incident');
 request.setBasicAuth("admin","admin");
 request.addHeader('Accept','application/json');
 request.addHeader('Content-Type','application/json');
 
 var response = request.post('{"short_description":"Test me"}');
 
 gs.log(response.getStatusCode());
 gs.log(response.getBody());

PUT

 var request = new GlideHTTPRequest
           ('https://myinstance.service-now.com/api/now/table/incident/0fbbeddad47e1100a92e188eafa1dd60');
 request.setBasicAuth("admin","admin");
 request.addHeader('Accept','application/json');
 request.addHeader('Content-Type','application/json');
 
 var response = request.put('{"short_description":"Test me update"}');
 
 gs.log(response.getStatusCode());
 gs.log(response.getBody());

PATCH

var request = new GlideHTTPRequest
           ('https://myinstance.service-now.com/api/now/table/incident/0fbbeddad47e1100a92e188eafa1dd60');
 request.setBasicAuth("admin","admin");
 request.addHeader('Accept','application/json');
 request.addHeader('Content-Type','application/json');
 
 var response = request.patch('{"short_description":"Test me patch update"}');
 
 gs.log(response.getStatusCode());
 gs.log(response.getBody());

DELETE

 var request = new GlideHTTPRequest
           ('https://myinstance/api/now/table/incident/0fbbeddad47e1100a92e188eafa1dd60');
 request.setBasicAuth("admin","admin");
 request.addHeader('Accept','application/json');
 request.addHeader('Content-Type','application/json');
 
 var response = request.del();
 
 gs.log(response.getStatusCode());
 gs.log(response.getBody());