ServiceNow's Scripted REST APIs follow a specific pattern that trips up developers coming from other platforms. The request and response objects are injected into the execution context, but unlike Express.js or similar frameworks, you must explicitly set headers and use getStreamWriter() to write response bodies. The biggest mistake developers make is assuming path parameters are automatically parsed as the correct data types—they're always strings and require explicit validation.
When to use Scripted REST APIs
- When you need custom business logic that the Table API doesn't support
- When integrating with external systems that require specific response formats
- When you need to aggregate data from multiple tables in a single request
- When you need custom authentication or authorization logic beyond ACLs
When NOT to use Scripted REST APIs
- Don't use for simple CRUD operations—use the Table API instead
- Don't use for high-volume operations without pagination—you'll hit execution limits
- Don't use for file uploads/downloads—use Attachment API or custom processors
- Don't use for real-time notifications—use Server-Sent Events or WebSocket endpoints
Key behaviors and gotchas
- Path parameters in
request.pathParamsare always strings, even numeric-looking values - You must explicitly call
response.setHeader('Content-Type', 'application/json')or responses default to text/plain - Request body parsing depends on Content-Type header—JSON isn't automatically parsed
- ACLs still apply to GlideRecord queries within the API—scope doesn't bypass security
- The API inherits the application scope it's defined in—cross-scope table access requires explicit permissions
- Execution time limit is 60 seconds—long-running operations will timeout
Always validate path parameters exist before using them. ServiceNow doesn't return 404 for missing path params—your script will execute with undefined values, leading to confusing errors or unintended behavior.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.