IT CanvassTalk to an advisor
Development · LessonReviewed by Praveen T, ServiceNow Trainer, 9 yrs · Updated · Published · current release · intermediate

ServiceNow Scripted REST APIs

Expose custom, secured REST endpoints from your instance for other systems to call.

Quick answer

A Scripted REST API is an inbound endpoint you define on a ServiceNow instance: an API with a base path such as /api/x_acme/orders, resources that pair a method and relative path with a script, and request.pathParams, queryParams and body.data to read from. Build one when the Table API is too broad or partners need a documented contract.

Key takeaways
  • Anatomy
  • When to build one
  • Try it Yourself

Where REST integrations let ServiceNow call out, Scripted REST APIs let ServiceNow be called. You define your own inbound endpoints, with custom paths, methods, query parameters and response shapes, so external systems integrate with exactly the contract you design, not raw table access.

Anatomy

  • API, the service, with a base path like /api/x_acme/orders.
  • Resource, a method + relative path (e.g. GET /{id}) with a script.
  • Request / Response, request.pathParams, request.queryParams, request.body.data; build the reply on response.
// GET /api/x_acme/orders/{id} (function process(request, response) { var id = request.pathParams.id; var gr = new GlideRecord('sc_request'); if (!gr.get(id)) { response.setStatus(404); return { error: 'not found' }; } return { number: gr.getValue('number'), state: gr.getValue('state') }; })(request, response);
Secure and version it. Scripted REST APIs honour ACLs and require authentication; scope them to a specific role. Put a version in the path (/v1/) from day one so you can evolve the contract without breaking existing callers.

When to build one

Use a Scripted REST API when the out-of-box Table API is too broad or the wrong shape, when you want to hide internal fields, aggregate data, or present a clean, documented contract to partners.

Try it YourselfJavaScript
▸ Press Run to execute.

Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.

Practise this on your own free instance.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support