Skip to content

Instantly share code, notes, and snippets.

View bryanbarnard's full-sized avatar
🕶️
building

Bryan Barnard bryanbarnard

🕶️
building
View GitHub Profile
@bryanbarnard
bryanbarnard / case.json
Created September 27, 2023 18:20
Example ServiceNow Customer Support Case
{
"result": [
{
"parent": "CS0001015",
"related_party_consumers": "",
"case_action_summary": "CAS0001001",
"caused_by": "",
"watch_list": "",
"related_party_users": "",
"active_escalation": "",
@bryanbarnard
bryanbarnard / index.js
Created September 3, 2019 00:25
sample connect to sniot mqtt
//index.js
var pwd = 'replace with password'
var opt = {username: "subscribe",port: 8883 ,password: pwd, rejectUnauthorized: false}
var mqtt = require('mqtt')
var client = mqtt.connect('mqtts://broker.iotdemo2-dev.sniot.net', opt)
client.on('connect', function () {
client.subscribe('sniothub/rules/message', function (err) {
if (!err) {
console.log("successfully connected")
@bryanbarnard
bryanbarnard / ccw3970_background_script_publish_message
Created April 14, 2017 13:44
CCW3970 Background Script - Publish Message
/*
Make HTTP Request using RESTMessageV2
*/
try {
var req = new sn_ws.RESTMessageV2('PubNub', 'Publish Message');
req.setStringParameterNoEscape('pub_key', 'pub-c-11b9ede6-f9ee-4da8-a829-944a45f29eb8');
req.setStringParameterNoEscape('client', gs.getProperty('instance_name') + '-' + gs.getProperty('instance_id'));
req.setStringParameterNoEscape('sub_key', 'sub-c-dafe9b8c-1ae1-11e7-bc52-02ee2ddab7fe');
req.setStringParameterNoEscape('channel', 'CCW3970');
@bryanbarnard
bryanbarnard / servicenow_rest_attachment_api_python_simple_binary_example.py
Created January 10, 2017 15:23
ServiceNow REST Attachment API Example Python Example using /now/attachment/file endpoint to post (upload) a file as an attachment to an incident as binary.
#Need to install requests package for python
#easy_install requests
import requests
# Request Docs: http://docs.python-requests.org/en/master/user/quickstart/
# Set the request parameters
url = 'https://bbarnsc1.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'
# url = 'https://fejr5sb8ead6.runscope.net/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'
@bryanbarnard
bryanbarnard / servicenow_rest_attachment_api_python_mulitpart_example.py
Last active February 2, 2022 17:51
ServiceNow REST Attachment API Example Python Example using /now/attachment/upload endpoint to post (upload) a file as an attachment to an incident as multipart form data.
# This example uses the Python Requests Library and you will need to install requests package for python
# Documentation can be found at http://docs.python-requests.org/en/master/user/quickstart/
import requests
import pprint
import json
# Specify the Endpoint URL replacing {servicenow_instance_name} with your ServiceNow Instance Name
url = 'https://{servicenow_instance_name}.service-now.com/api/now/attachment/upload'
@bryanbarnard
bryanbarnard / sample.js
Created June 20, 2016 03:24
Using getResponseAttachmentSysid()
var tablename = 'incident';
var recordSysId = '3197671513d75200a54fb8b12244b0f6';
var filename = 'new_image.jpeg';
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('https://demonightlyus.service-now.com/api/now/attachment/2b6644b15f1021001c9b2572f2b47763/file');
request.saveResponseBodyAsAttachment(tablename, recordSysId, filename);
request.setBasicAuth('admin', '{update_with_password');
@bryanbarnard
bryanbarnard / sample_outbound_http.js
Last active April 14, 2016 23:08
Sample Outbound HTTP Request with RESTMessageV2 - Scripted
/**
* sample http request using RESTMessageV2 server side api
*/
(function sample_http_request() {
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('https://api.myjson.com/bins/4j985');
@bryanbarnard
bryanbarnard / servicenow_sample_http_request.js
Created March 8, 2016 17:51
sample http request in servicenow using RESTMessageV2 server side api tested running in ServiceNow Geneva Release as a background script in global scope
/**
* sample http request in servicenow using RESTMessageV2 server side api
* tested running in ServiceNow Geneva Release as a background script in global scope
*/
(function sample_http_request() {
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('https://api.myjson.com/bins/4j985');
@bryanbarnard
bryanbarnard / sample_response_dot_walk.http
Created September 25, 2015 21:38
Sample Response to a ServiceNow Demo Instance - using sysparm_fields dot-walk
HTTP/1.1 200 OK
Link: <https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number%2Clocation%2Clocation.name%2Clocation.city&sysparm_offset=0>;rel="first",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number%2Clocation%2Clocation.name%2Clocation.city&sysparm_offset=-1>;rel="prev",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number%2Clocation%2Clocation.name%2Clocation.city&sysparm_offset=1>;rel="next",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number%2Clocation%2Clocation.name%2Clocation.city&sysparm_offset=549>;rel="last"
X-Total-Count: 550
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 25 Sep 2015 21:33:32 GMT
Server: ServiceNow
Connection: close
{
@bryanbarnard
bryanbarnard / sample_request_dot_walk.http
Created September 25, 2015 21:34
Sample Request to a ServiceNow Demo Instance - using sysparm_fields dot-walk
GET /api/now/table/incident?sysparm_limit=1&sysparm_fields=number%2Clocation%2Clocation.name%2Clocation.city HTTP/1.1
Authorization: <removed>
Accept: application/json
Host: demo003.service-now.com
Connection: close