ServiceNow Incidents

Basic interactions with ServiceNow for testing APIs in incident response flows.

After instantiating the ServiceNow instance, you can either get incidents or create incidents. These are basic examples of how to interact with the ServiceNow API and should be built upon depending on need.

Get a ServiceNow developer instance here
See here for information on ServiceNow's API Explorer.

[{"id":"a538e06a.cfed5","type":"subflow","name":"get-incident","info":"","category":"ServiceNow","in":[{"x":140,"y":180,"wires":[{"id":"a526d17c.a46e3"}]}],"out":[{"x":1940,"y":140,"wires":[{"id":"62f9b6be.0d1258","port":0}]},{"x":1940,"y":220,"wires":[{"id":"69cc935c.bd621c","port":0}]}],"env":[],"status":{"x":320,"y":80,"wires":[{"id":"79fba0d8.bd0f2","port":0}]}},{"id":"3c258348.1cc89c","type":"function","z":"a538e06a.cfed5","name":"Prepare Request","func":"msg.url = [msg.cb.url, 'api/now/table/incident'].join('/');\n\nmsg.headers = {\n    'authorization': [msg.cb.custom_api_key, msg.cb.custom_api_id].join('/'),\n    'Content-Type': 'Basic ' + msg.sn.auth\n};\n\nmsg.payload = msg.sn.body;\ndelete msg.sn.body;\ndelete msg.sn.auth;\n\nreturn msg;","outputs":1,"noerr":0,"x":1190,"y":180,"wires":[["505a2109.4c85e"]]},{"id":"505a2109.4c85e","type":"http request","z":"a538e06a.cfed5","name":"get incident","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","proxy":"","authType":"","x":1390,"y":180,"wires":[["45ba0e54.457a5"]]},{"id":"45ba0e54.457a5","type":"switch","z":"a538e06a.cfed5","name":"status code","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1570,"y":180,"wires":[["62f9b6be.0d1258"],["69cc935c.bd621c"]]},{"id":"79fba0d8.bd0f2","type":"status","z":"a538e06a.cfed5","name":"","scope":["62f9b6be.0d1258","a526d17c.a46e3","69cc935c.bd621c"],"x":200,"y":80,"wires":[[]]},{"id":"62f9b6be.0d1258","type":"function","z":"a538e06a.cfed5","name":"set status","func":"node.status({\n    fill: 'green',\n    text: msg.payload.name\n})\n\nreturn msg;","outputs":1,"noerr":0,"x":1780,"y":140,"wires":[[]]},{"id":"a526d17c.a46e3","type":"function","z":"a538e06a.cfed5","name":"set status","func":"if (!msg.cb) {\n    node.status({\n        fill: 'red',\n        text: 'cb not instantiated'\n    });\n    return;\n}\n\nelse {\n    node.status({\n        fill: 'grey',\n        text: 'getting device ' + msg.payload\n    });\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":180,"wires":[["d2ecb83c.3a4c28"]]},{"id":"69cc935c.bd621c","type":"function","z":"a538e06a.cfed5","name":"set status","func":"node.status({\n    fill: 'red',\n    shape: 'ring',\n    text: [msg.statusCode, msg.payload.message].join(': ')\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":1780,"y":220,"wires":[[]]},{"id":"d2ecb83c.3a4c28","type":"delay","z":"a538e06a.cfed5","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":180,"wires":[["cb972086.11f88"]]},{"id":"5b951bc2.0f44e4","type":"base64","z":"a538e06a.cfed5","name":"encode credentials","action":"str","property":"sn.auth","x":950,"y":180,"wires":[["3c258348.1cc89c"]]},{"id":"cb972086.11f88","type":"function","z":"a538e06a.cfed5","name":"prepare authentication","func":"msg.sn.body = msg.payload;\nmsg.sn.auth = [msg.sn.username, ms.sn.password].join(':');\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":180,"wires":[["5b951bc2.0f44e4"]]},{"id":"6602dbf.7812b24","type":"subflow","name":"create-incident","info":"","category":"ServiceNow","in":[{"x":160,"y":180,"wires":[{"id":"d0757d31.3542b"}]}],"out":[{"x":1860,"y":140,"wires":[{"id":"d65e5913.113278","port":0}]},{"x":1860,"y":220,"wires":[{"id":"21531c4f.cf2374","port":0}]}],"env":[],"status":{"x":320,"y":80,"wires":[{"id":"9ea9dc75.c1806","port":0}]}},{"id":"748f26c2.1e0928","type":"function","z":"6602dbf.7812b24","name":"create ticket","func":"msg.url = [msg.cb.url, 'api/now/table/incident'].join('/');\n\nmsg.headers = {\n    'authorization': [msg.cb.custom_api_key, msg.cb.custom_api_id].join('/'),\n    'Content-Type': 'Basic ' + msg.sn.auth\n};\n\nmsg.payload = msg.sn.body;\ndelete msg.sn.body;\ndelete msg.sn.auth;\n\nreturn msg;","outputs":1,"noerr":0,"x":1110,"y":180,"wires":[["fbc92c75.e7653"]]},{"id":"fbc92c75.e7653","type":"http request","z":"6602dbf.7812b24","name":"create incident","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","proxy":"","authType":"","x":1320,"y":180,"wires":[["c18462bf.e06bf"]]},{"id":"c18462bf.e06bf","type":"switch","z":"6602dbf.7812b24","name":"status code","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1510,"y":180,"wires":[["d65e5913.113278"],["21531c4f.cf2374"]]},{"id":"9ea9dc75.c1806","type":"status","z":"6602dbf.7812b24","name":"","scope":["d65e5913.113278","d0757d31.3542b","21531c4f.cf2374"],"x":200,"y":80,"wires":[[]]},{"id":"d65e5913.113278","type":"function","z":"6602dbf.7812b24","name":"set status","func":"node.status({\n    fill: 'green',\n    text: msg.payload.name\n})\n\nreturn msg;","outputs":1,"noerr":0,"x":1720,"y":140,"wires":[[]]},{"id":"d0757d31.3542b","type":"function","z":"6602dbf.7812b24","name":"set status","func":"if (!msg.cb) {\n    node.status({\n        fill: 'red',\n        text: 'cb not instantiated'\n    });\n    return;\n}\n\nelse {\n    node.status({\n        fill: 'grey',\n        text: 'getting device ' + msg.payload\n    });\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":180,"wires":[["f80c6412.5cef78"]]},{"id":"21531c4f.cf2374","type":"function","z":"6602dbf.7812b24","name":"set status","func":"node.status({\n    fill: 'red',\n    shape: 'ring',\n    text: [msg.statusCode, msg.payload.message].join(': ')\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":1720,"y":220,"wires":[[]]},{"id":"f80c6412.5cef78","type":"delay","z":"6602dbf.7812b24","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":180,"wires":[["fc03388b.4d5a58"]]},{"id":"916eda48.9b44a8","type":"base64","z":"6602dbf.7812b24","name":"","action":"str","property":"sn.auth","x":920,"y":180,"wires":[["748f26c2.1e0928"]]},{"id":"fc03388b.4d5a58","type":"function","z":"6602dbf.7812b24","name":"prepare authentication","func":"msg.sn.body = msg.payload;\nmsg.sn.auth = [msg.sn.username, ms.sn.password].join(':');\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":180,"wires":[["916eda48.9b44a8"]]},{"id":"fedd182.e0ce6e8","type":"subflow","name":"initialize","info":"","category":"ServiceNow","in":[{"x":160,"y":140,"wires":[{"id":"82011eac.ee18f"}]}],"out":[{"x":600,"y":140,"wires":[{"id":"246ea08e.5c881","port":0}]}],"env":[],"status":{"x":320,"y":80,"wires":[{"id":"eb7b489a.3dcfb8","port":0}]}},{"id":"82011eac.ee18f","type":"change","z":"fedd182.e0ce6e8","name":"","rules":[{"t":"set","p":"sn.url","pt":"msg","to":"URL","tot":"env"},{"t":"set","p":"sn.username","pt":"msg","to":"USERNAME","tot":"env"},{"t":"set","p":"sn.password","pt":"msg","to":"PASSWORD","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":140,"wires":[["246ea08e.5c881"]]},{"id":"246ea08e.5c881","type":"function","z":"fedd182.e0ce6e8","name":"set status","func":"node.status({\n    fill: 'green',\n    text: 'instantiated'\n});\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":140,"wires":[[]]},{"id":"eb7b489a.3dcfb8","type":"status","z":"fedd182.e0ce6e8","name":"","scope":null,"x":200,"y":80,"wires":[[]]},{"id":"ee7d7e15.e8ad","type":"subflow:fedd182.e0ce6e8","z":"3c0945fd.ca1b9a","name":"","env":[],"x":830,"y":840,"wires":[[]]},{"id":"5fb39144.5f9c2","type":"subflow:6602dbf.7812b24","z":"3c0945fd.ca1b9a","name":"","env":[],"x":860,"y":920,"wires":[[],[]]},{"id":"e4f45b14.d264a8","type":"subflow:a538e06a.cfed5","z":"3c0945fd.ca1b9a","name":"","env":[],"x":850,"y":880,"wires":[[],[]]}]

Flow Info

Created 5 years, 7 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • delay (x2)
  • function (x11)
  • http request (x2)
  • status (x3)
  • switch (x2)
Other
  • base64 (x2)
  • subflow (x3)
  • subflow:6602dbf.7812b24 (x1)
  • subflow:a538e06a.cfed5 (x1)
  • subflow:fedd182.e0ce6e8 (x1)

Tags

  • ServiceNow
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option