Build a REST integration
Quick answer
End to end: connection alias, credential, REST message, flow action and error handling.
Key takeaways
- Connection aliases keep environments separate
- Test the method before writing code
- Handle non success codes explicitly
- Log correlation ids and name an owner
Set up connection and credential
Create a credential record for the secret and a connection alias pointing at the endpoint. Each environment gets its own connection record under the same alias, so nothing in your logic changes between dev, test and production.
Create the REST message
Add the message and one method per operation, using the alias rather than a hard coded URL. Use the Test link to confirm the call works before writing any code.
Call it from automation
Prefer a flow action so the integration is visible to non developers, and add error handling.
// script step or script include used by the action
var r = new sn_ws.RESTMessageV2('Acme Orders', 'createOrder');
r.setRequestBody(JSON.stringify(payload));
r.setHttpTimeout(15000);
var resp = r.execute();
var code = resp.getStatusCode();
return { status: code, body: code == 201 ? resp.getBody() : resp.getErrorMessage() };Make it operable
Log the correlation id returned by the provider, alert on repeated failures, and document who to call when the endpoint is down. An integration without an owner becomes an outage nobody can fix.
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
What keeps the endpoint different per environment?
- A. A system property in each flow
- B. A connection alias with per environment connection records
- C. Separate flows
- D. Separate scopes
Show answer
B. A connection alias with per environment connection records
One alias resolves to the connection record for that instance.
What should a call always set?
- A. A timeout
- B. A UI action
- C. An ACL
- D. A dashboard
Show answer
A. A timeout
Without a timeout a slow endpoint ties up a worker.