IT CanvassTalk to an advisor
Development · LessonBy , ServiceNow Trainer, 9 yrs · Published · current release · intermediate

Scripted REST APIs

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

Quick answer

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.

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.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
A Scripted REST API lets ServiceNow...

Frequently asked questions

What does the term Scripted REST APIs refer to in ServiceNow?
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.
Which systems are connected to Scripted REST APIs?
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.
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