Package: people-analytics-itsm-sdk
people-analytics-itsm-sdkInteract with various ServiceNow functionality within your python application, includes the ability to perform create, read, update, and delete (CRUD) operations on existing tables, insert data into, retrieve information from and submit tickets.Installation# or PyPIpipinstallpeople-analytics-itsm-sdkEnvironment variablesTo use people-analytics-itsm-sdk library, you need set four environment variables:# ---DOTENV EXAMPLE---
ITSM_SERVICENOW_URL=https://service-now.com # base url of you servicenow server
ITSM_SERVICENOW_API_TOKEN= # servicenow auth token
ITSM_SERVICENOW_API_USER= # servicenow user
ITSM_SERVICENOW_API_PASSWORD= # servicenow user password

# you can choose beetwen user and password or api token to authenticationWe recommended you to create a.envfile in your project root to set environment variables.Coding in Windows OSOn coding in Windows OS, you need set the environment variables before import people-analytics-itsm-sdk libraryimportos# set environment variables before import people-analytics-itsm-sdk libraryos.environ["ITSM_SERVICENOW_URL"]="https://your-service-now-base-path.com"os.environ["ITSM_SERVICENOW_API_TOKEN"]="Your api token"os.environ["ITSM_SERVICENOW_API_USER"]="your.user.email@domain.com"os.environ["ITSM_SERVICENOW_API_PASSWORD"]="your password"frompeople_analytics_itsm_sdk.sdkimportRecordsExample UsageGet data from servicenow tableTo get data from servicenow table, we useRecordsclass.frompeople_analytics_itsm_sdk.sdkimportRecords# This code get all records in one servicenow tabletable_name="sys_user"# replace this with table name are you needrecords=Records(table=table_name)table_data=records.all()# all() method return all recordsQueryingYou can apply filters and select columns in the table usingRecords().querymethod. For example:fromdatetimeimportdatetime,timedeltafrompeople_analytics_itsm_sdk.sdkimportRecordstable_name="incident"records=Records(table=table_name)# define date interval to filterstart=datetime(1970,1,1)end=datetime.now()-timedelta(days=20)# query registers of incident with number started with 'INC0123', created between 1970-01-01 and 20 days old.records.query.field('number').starts_with('INC0123')\.AND().field('sys_created_on').between(start,end)\.AND().field('sys_updated_on').order_descending()data=records.all()# return all records of queryUpdate tablesto create, delete and update records in a servicenow table, you can useManagerclass.frompeople_analytics_itsm_sdk.sdkimportManagertable_name="name of table you need update"manager=Manager(table=table_name)# create new register in table exampleregister_to_create={"field1":"value1","field2":"value2",}manager.create(data=register_to_create)# update register in table exampleregister_update_sys_id="id of register you need update"register_data_to_update={"field1":"value4"}manager.update(sys_id=register_update_sys_id,data=register_data_to_update)# delete register in table exampleregister_delete_sys_id="id of register you need delete"manager.delete(sys_id=register_delete_sys_id)Submit ticketsTo submit tickets, you can useProducerServiceCatalogclass.frompeople_analytics_itsm_sdk.sdkimportProducerServiceCatalogsurvey_catalog_id="id of your ticket survey in servicenow catalog"variables={"question1":"value1","question2":"value2"}producer_catalog=ProducerServiceCatalog()result=producer_catalog.store(catalog_id=survey_catalog_id,variables=variables)Query paramsfield(field)Define the field to operateparameters: field – field (str) to operateorder_descending()Define a order descending of fieldorder_ascending()Define a order ascending of fieldstarts_with(starts_with)adds new STARTSWITH conditionparameters: starts_with – field of correspondence starts with a value providedends_with(ends_with)adds new ENDSWITH conditionparameters: ends_with – field of correspondence ends with a value providedcontains(contains)adds new LIKE conditionparameters: contains – field of correspondence contains the value providednot_contains(not_contains)adds new NOTLIKE conditionparameters: not_contains – field of correspondence not contains the value providedis_empty()adds new ISEMPTY conditionis_not_empty()adds new ISNOTEMPTY conditionequals(data)adds new IN or EQUALS condition depending on whether a list or string had providedparameters:
data –stringorlistof valuesraise:
QueryTypeError: if the data provided are of an unexpected kindnot_equals(data)adds a new NOT IN ou EQUALS condition depending on whether alistorstringhad providedparameters:
data –stringorlistof valuesraise:
QueryTypeError: if the data provided are of an unexpected kindgreater_than(greater_than)adds a new GREATER THAN conditionparameters:
greater_than – object compatible withstringordatetime(naive UTC datetime or tz-aware datetime)raise:
QueryTypeError: if greater_than provided are of an unexpected kindless_than(less_than)adds new LESS THAN conditionparameters:
less_than – object compatible withstringordatetime(naive UTC datetime or tz-aware datetime)raise:
QueryTypeError: if less_than provided are of an unexpected kindbetween(start, end)adds a new BETWEEN conditionparameters:
start – object compatible withintegerordatetime(in the user's time zone SNOW)
end – object compatible withintegerordatetime(in the user's time zoneSNOW)raise:
QueryTypeError: if the initial or final arguments are of an invalid typeAND()adds a new AND operatorOR()adds a new OR operatorNQ()adds a new NQ operator (new query)