Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

=======
## 1.5.0
- Add support of PySNow Resource API via `use_new_service_now_api` flag.
- Add support for returning specific fields on "get".

## 1.0.0

* Drop Python 2.7 support
Expand Down
7 changes: 7 additions & 0 deletions actions/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

class DeleteAction(BaseAction):
def run(self, table, sysid):
# If using new ServiceNew API...
if self.config['use_new_service_now_api']:
client = self.client
resource = client.resource(api_path="/table/{0}".format(table))
response = resource.delete(query={"sys_id": sysid}) # pylint: disable=no-member
return response

s = self.client
r = s.query(table=table, query={'sys_id': sysid}) # pylint: disable=no-member
response = r.delete() # pylint: disable=no-member
Expand Down
15 changes: 14 additions & 1 deletion actions/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@


class GetAction(BaseAction):
def run(self, table, query):
def run(self, table, query, fields=[]):
# If using new ServiceNew API...
if self.config['use_new_service_now_api']:
client = self.client
resource = client.resource(api_path="/table/{0}".format(table))
if not fields:
response = resource.get(query=query)
else:
response = resource.get(query=query, fields=fields)
output = []
for each_item in response.all():
output.append(each_item)
return output

s = self.client
r = s.query(table=table, query=query) # pylint: disable=no-member
response = r.get_all() # pylint: disable=no-member
Expand Down
4 changes: 4 additions & 0 deletions actions/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ parameters:
type: "object"
description: "Structured query for SN data"
required: true
fields:
type: "array"
description: "Comma-separated list of fields to return. ***Only supported when config parameter use_new_service_now_api is true***"
required: false
7 changes: 7 additions & 0 deletions actions/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

class InsertAction(BaseAction):
def run(self, table, payload):
# If using new ServiceNew API...
if self.config['use_new_service_now_api']:
client = self.client
resource = client.resource(api_path="/table/{0}".format(table))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nicer to use python fstrings instead of format strings now that we are python 3 only, e.g. api_path=f"/table/{table}" for simplicity, but not essential. Applies to other places as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Amanda! This is a good suggestion; I'll keep this in mind in the future. I'm a little set in my ways about format() and adjusting to fstrings. :)

response = resource.create(payload=payload) # pylint: disable=no-member
return response

s = self.client
response = s.insert(table=table, payload=payload) # pylint: disable=no-member
return response
7 changes: 7 additions & 0 deletions actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

class UpdateAction(BaseAction):
def run(self, table, payload, sysid):
# If using new ServiceNew API...
if self.config['use_new_service_now_api']:
client = self.client
resource = client.resource(api_path="/table/{0}".format(table))
response = resource.update(query={"sys_id": sysid}, payload=payload) # pylint: disable=no-member
return response

s = self.client
r = s.query(table=table, query={'sys_id': sysid}) # pylint: disable=no-member
response = r.update(payload) # pylint: disable=no-member
Expand Down
6 changes: 6 additions & 0 deletions config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@
description: "ServiceNow options that will be passed to all requests"
type: object
required: false
use_new_service_now_api:
description: "Use the new ServiceNow APIs to avoid deprecation warnings."
type: "boolean"
secret: false
required: false
default: true
2 changes: 1 addition & 1 deletion pack.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: ServiceNow Integration Pack
keywords:
- servicenow
- incident management
version: 1.0.0
version: 1.5.0
python_versions:
- "3"
author: James Fryman
Expand Down