Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
building

Bryan Barnard bryanbarnard

🕶️
building
View GitHub Profile
@bryanbarnard
bryanbarnard / index.js
Created Sep 3, 2019
sample connect to sniot mqtt
View index.js
//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 Apr 14, 2017
CCW3970 Background Script - Publish Message
View 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 Jan 10, 2017
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.
View servicenow_rest_attachment_api_python_simple_binary_example.py
#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 Feb 2, 2022
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.
View servicenow_rest_attachment_api_python_mulitpart_example.py
# 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 Jun 20, 2016
Using getResponseAttachmentSysid()
View sample.js
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 Apr 14, 2016
Sample Outbound HTTP Request with RESTMessageV2 - Scripted
View sample_outbound_http.js
/**
* 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 Mar 8, 2016
sample http request in servicenow using RESTMessageV2 server side api tested running in ServiceNow Geneva Release as a background script in global scope
View servicenow_sample_http_request.js
/**
* 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 Sep 25, 2015
Sample Response to a ServiceNow Demo Instance - using sysparm_fields dot-walk
View sample_response_dot_walk.http
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 Sep 25, 2015
Sample Request to a ServiceNow Demo Instance - using sysparm_fields dot-walk
View sample_request_dot_walk.http
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
@bryanbarnard
bryanbarnard / sample_response_sysparm_fields.http
Created Sep 25, 2015
Sample Response - using sysparm_fields to limit response
View sample_response_sysparm_fields.http
HTTP/1.1 200 OK
Link: <https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number&sysparm_offset=0>;rel="first",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number&sysparm_offset=-1>;rel="prev",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number&sysparm_offset=1>;rel="next",<https://demo003.service-now.com/api/now/table/incident?sysparm_limit=1&sysparm_fields=number&sysparm_offset=549>;rel="last"
X-Total-Count: 550
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 25 Sep 2015 21:08:44 GMT
Server: ServiceNow
Connection: close
{"result":[{"number":"INC0000001"}]}