IT CanvassTalk to an advisor
How-to Guides · LessonBy , ServiceNow Architect · Published · ServiceNow · all levels

Build a REST integration

End to end: connection alias, credential, REST message, flow action and error handling.

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.

Practice challenge

+0 XPStreak ×0
Question 1 of 2
What keeps the endpoint different per environment?

Frequently asked questions

Flow action or business rule?
Flow action, so the integration is visible and reusable. Keep script to the part that genuinely needs it.
How do we handle retries?
Use the flow retry policy for transient failures, and make the remote call idempotent by sending a client generated key.
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