Ejemplo n.º 1
0
def gettkts():
	username, password, instance = session['username'], session['password'], 'wiprodemo'
	s = sn.Client(instance,username,password) 
	s.table="incident" 
	try:
		res = s.get({"sys_created_by": username, "sysparm_limit":"5"}) 
		print str(res)
		return json.dumps(res)
	except sn.UnexpectedResponse as e:  # Unexpected server response (i.e. authentication error)
		print(e)
Ejemplo n.º 2
0
def createTickets(categ, subcategory,shortdec,comments,priority):
	username, password, instance = session['username'], session['password'], 'wiprodemo'
	s = sn.Client(instance,username,password)
	s.table = 'incident'
	#strJSON = {"category":double_quote(categ),"sub_category":double_quote(subcategory),"short_description":double_quote(shortdec),"comments":double_quote(comments)}"
	strJSON={}
	strJSON['category']=categ
	strJSON['sub_category']=subcategory
	strJSON['short_description']=shortdec
	strJSON['comments']=comments
	strJSON['contact_type']='Self-service'
	strJSON['urgency']=priority
	strJSON['state']=1
	print strJSON

	try:
		
		res = s.insert(strJSON)
		print(res)
	except sn.UnexpectedResponse as e:  # Unexpected server response (i.e. authentication error)
		print(e)
Ejemplo n.º 3
0
def _get_client():
    config = __salt__['config.option'](SERVICE_NAME)
    instance_name = config['instance_name']
    username = config['username']
    password = config['password']
    return api_client.Client(instance_name, username, password)
Ejemplo n.º 4
0
 def setUp(self):
     global sn_auth
     self.sn = sn.Client(sn_auth['instance'], sn_auth['user'],
                         sn_auth['pass'])
     self.sn.table = 'incident'
Ejemplo n.º 5
0
You then take the cliendId and client secret values and input them in the
variables included in the below script.

The username required for authentication needs to have the itil role assigned
as well as the snc_platform_rest_api_access

This script can be further developed to query other ServiceNow tables as required

I use it mostly to query the ServiceNow table structures from within PowerBI

"""

import servicenow_rest.api as sn  #imports custom snow REST API library --> https://github.com/AMMullan/python-servicenow-rest
import requests

s = sn.Client('instance_name.service-now.com', 'user', 'pass')

#Define start and end date
year = 2019
month = 9
startdate = str(year) + "-" + str(month) + "-1"
enddate = str(year) + "-" + str(month)

#Sets the first POST request to the instance sending our OAuth 2.0 token

url_o = "https://instance_name.service-now.com/oauth_token.do"
post_body = {
    'content_type': 'application/json',
    'grant_type': 'password',
    'client_id': 'cl_id',
    'client_secret': 'cl_secret',