Skip to content

Developer track

Integrations

Outbound calls, inbound APIs and where to look when they break.

3 sections · 21 entries

Integration snippets

Patterns we use on real integration work, stripped to the essentials.

Outbound REST with error handling

Use a REST Message record for the endpoint and auth; keep secrets out of scripts.

try {
  var rm = new sn_ws.RESTMessageV2('x_rsa_vendor_api', 'get_ticket');
  rm.setStringParameterNoEscape('id', current.getValue('correlation_id'));
  rm.setHttpTimeout(30000);
  var res = rm.execute();
  var status = res.getStatusCode();
  if (res.haveError() || status >= 400) {
    gs.error('Vendor API ' + status + ': ' + res.getErrorMessage());
  } else {
    var body = JSON.parse(res.getBody());
    // map body -> fields
  }
} catch (e) {
  gs.error('Vendor API call failed: ' + e.message);
}

Scripted REST resource

Validate input, return clear status codes, never trust the caller.

(function process(request, response) {
  var body = request.body.data;
  if (!body || !body.short_description) {
    response.setStatus(400);
    return { error: 'short_description is required' };
  }
  var inc = new GlideRecord('incident');
  inc.initialize();
  inc.setValue('short_description', body.short_description);
  var id = inc.insert();
  response.setStatus(201);
  return { sys_id: id, number: inc.getValue('number') };
})(request, response);

Start a flow or subflow from scriptHidden gem

FlowAPI runs Flow Designer logic from a script. Use the scoped name of your flow.

var inputs = { current: current, table_name: current.getTableName() };
// Asynchronous: returns immediately
sn_fd.FlowAPI.getRunner()
  .subflow('x_rsa_app.notify_vendor')
  .inBackground()
  .withInputs(inputs)
  .run();

Integration pages

Where to look when an integration misbehaves.

Outbound REST messages and their methods
Scripted REST APIs you have built
Outbound HTTP log: request, response and timing per callHidden gem
ECC queue: everything going to and from MID Servers
MID Servers and their status
OAuth application registries (inbound and outbound)
Data sources for imports
Transform maps
Import set rows: see why a row was skipped or erroredHidden gem
Flows and subflows
Flow executions: open one to see each step’s inputs and outputsHidden gem

Integration checklist

Run through this before you call an integration done.

  • ✦Idempotent. Retries must not create duplicates: match on a correlation ID before inserting.
  • ✦Retries. Retry 429s and 5xx with backoff; never retry 4xx validation errors.
  • ✦Timeouts. Set an explicit HTTP timeout on every outbound call.
  • ✦Credentials. Credentials live in auth profiles or connection aliases, never in scripts.
  • ✦Async. Call slow APIs from async business rules, events or flows, not before rules.
  • ✦Logging. Log the status code and correlation ID, never the full payload with personal data.
  • ✦Alerting. Someone gets told when a call fails three times in a row.

Snippets are provided as-is under the MIT licence, without warranty. Test in a sub-production instance first. ServiceNow is a trademark of ServiceNow, Inc.; this page is independent and not affiliated with or endorsed by ServiceNow.