Skip to content

Commit

Permalink
Servicenow api fix (#29433)
Browse files Browse the repository at this point in the history
* Fixed an issue with api version v2 in mirror in

* Added release notes

* Bump pack from version ServiceNow to 2.5.40.

* Update docs

* Fixed test

* Fixed DS108

---------

Co-authored-by: Content Bot <bot@demisto.com>
  • Loading branch information
Shellyber and Content Bot authored Sep 6, 2023
1 parent 198f31f commit bfe715f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Packs/ServiceNow/Integrations/ServiceNowv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Retrieves ticket information by ticket ID.
| id | Ticket system ID for which to retrieve information. | Optional |
| ticket_type | Ticket type. Can be "incident", "problem", "change_request", "sc_request", "sc_task", "sc_req_item", or "sn_si_incident". Default is "incident". | Optional |
| number | Ticket number to retrieve. | Optional |
| get_attachments | If "true" will retrieve ticket attachments. Default is "false". | Optional |
| get_attachments | If "true" will retrieve ticket attachments.Note this option will always use the v1 API version, as it is not supported in v2. Default is "false". | Optional |
| custom_fields | Custom fields on which to query. For example: state_code=AR,time_zone=PST. | Optional |
| additional_fields | Additional fields to display in the War Room entry and incident context. | Optional |

Expand Down
9 changes: 7 additions & 2 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def generic_request(self, method: str, path: str, body: Optional[Dict] = None, h

def send_request(self, path: str, method: str = 'GET', body: dict | None = None, params: dict | None = None,
headers: dict | None = None, file=None, sc_api: bool = False, cr_api: bool = False,
no_record_found_res: dict = {'result': []}):
get_attachments: bool = False, no_record_found_res: dict = {'result': []}):
"""Generic request to ServiceNow.
Args:
Expand All @@ -668,6 +668,7 @@ def send_request(self, path: str, method: str = 'GET', body: dict | None = None,
file: request file
sc_api: Whether to send the request to the Service Catalog API
cr_api: Whether to send the request to the Change Request REST API
get_attachments: if to get attachments or not.
Returns:
response from API
Expand All @@ -687,6 +688,10 @@ def send_request(self, path: str, method: str = 'GET', body: dict | None = None,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
# The attachments table does not support v2 api version
if get_attachments:
url = url.replace('/v2', '/v1')

max_retries = 3
num_of_tries = 0
while num_of_tries < max_retries:
Expand Down Expand Up @@ -831,7 +836,7 @@ def get_ticket_attachments(self, ticket_id: str, sys_created_on: Optional[str] =
query = f'table_sys_id={ticket_id}'
if sys_created_on:
query += f'^sys_created_on>{sys_created_on}'
return self.send_request('attachment', 'GET', params={'sysparm_query': query})
return self.send_request('attachment', 'GET', params={'sysparm_query': query}, get_attachments=True)

def get_ticket_attachment_entries(self, ticket_id: str, sys_created_on: Optional[str] = None) -> list:
"""Get ticket attachments, including file attachments
Expand Down
68 changes: 34 additions & 34 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ script:
name: number
- auto: PREDEFINED
defaultValue: 'false'
description: If "true" will retrieve ticket attachments. Default is "false".
description: If "true" will retrieve ticket attachments.Note this option will always use the v1 API version, as it is not supported in v2. Default is "false".
name: get_attachments
predefined:
- 'true'
Expand Down Expand Up @@ -397,7 +397,7 @@ script:
name: caller_id
- description: Category of the ticket.
name: category
- description: UID Format
- description: UID Format.
name: caused_by
- auto: PREDEFINED
description: Ticket's close code. Can be "Solved (Work Around)", "Solved (Permanently)", "Solved Remotely (Work Around)", "Solved Remotely (Permanently)", "Not Solved (Not Reproducible)", "Not Solved (Too Costly)", or "Closed/Resolved by Caller".
Expand Down Expand Up @@ -460,11 +460,11 @@ script:
- '0'
- description: Order number.
name: order
- description: UID Format
- description: UID Format.
name: parent
- description: UID Format
- description: UID Format.
name: parent_incident
- description: UID Format
- description: UID Format.
name: problem_id
- description: The number of users included in this ticket.
name: reassignment_count
Expand All @@ -474,7 +474,7 @@ script:
name: resolved_at
- description: ID of the user that resolved the ticket.
name: resolved_by
- description: UID
- description: UID.
name: rfc
- description: 'SLA due date/time, in the format: YYYY-MM-DD HH:MM:SS.'
name: sla_due
Expand All @@ -488,9 +488,9 @@ script:
name: user_input
- description: A list of watched tickets.
name: watch_list
- description: 'Format: YYYY-MM-DD HH:MM:SS'
- description: 'Format: YYYY-MM-DD HH:MM:SS.'
name: work_end
- description: Format journal list
- description: Format journal list.
name: work_notes
- description: List work notes UIDs.
name: work_notes_list
Expand Down Expand Up @@ -523,15 +523,15 @@ script:
- normal
- standard
- emergency
- description: 'State of the ticket, for example: "Closed" or "7" or "7 - Closed"'
- description: 'State of the ticket, for example: "Closed" or "7" or "7 - Closed".'
name: state
- description: ' Date/time the ticket was opened, in the format: YYYY-MM-DD HH:MM:SS.'
name: opened_at
- description: Caller system ID.
name: caller
- description: Ticket approval.
name: approval
- description: 'Additional fields in the format: fieldname1=value;fieldname2=value;'
- description: 'Additional fields in the format: fieldname1=value;fieldname2=value;.'
name: additional_fields
- auto: PREDEFINED
defaultValue: 'false'
Expand Down Expand Up @@ -735,21 +735,21 @@ script:
name: resolved_at
- description: Resolved by (UID format).
name: resolved_by
- description: UID
- description: UID.
name: rfc
- description: 'SLA due date/time, in the format: YYYY-MM-DD HH:MM:SS.'
name: sla_due
- description: Ticket subcategory.
name: subcategory
- description: Last updated by
- description: Last updated by.
name: sys_updated_by
- description: Date/time the system was last updated.
name: sys_updated_on
- description: Input from the end user.
name: user_input
- description: A list of watched tickets.
name: watch_list
- description: 'Format: YYYY-MM-DD HH:MM:SS'
- description: 'Format: YYYY-MM-DD HH:MM:SS.'
name: work_end
- description: Format journal list.
name: work_notes
Expand Down Expand Up @@ -791,7 +791,7 @@ script:
name: caller
- description: Ticket approval.
name: approval
- description: 'Additional fields in the format: fieldname1=value;fieldname2=value;'
- description: 'Additional fields in the format: fieldname1=value;fieldname2=value;.'
name: additional_fields
- auto: PREDEFINED
defaultValue: 'false'
Expand All @@ -818,7 +818,7 @@ script:
description: Updates the specified ticket.
name: servicenow-update-ticket
- arguments:
- description: Ticket System ID
- description: Ticket System ID.
name: id
required: true
- auto: PREDEFINED
Expand Down Expand Up @@ -858,7 +858,7 @@ script:
- description: Additional fields to present in the War Room entry and incident context. Can be nested (in the form of field1.field2).
isArray: true
name: additional_fields
- description: 'System parameters in the format: fieldname1=value;fieldname2=value. For example: "sysparm_display_value=true;sysparm_exclude_reference_link=True"'
- description: 'System parameters in the format: fieldname1=value;fieldname2=value. For example: "sysparm_display_value=true;sysparm_exclude_reference_link=True".'
name: system_params
description: Retrieves ticket information according to the supplied query.
name: servicenow-query-tickets
Expand Down Expand Up @@ -1013,7 +1013,7 @@ script:
description: A time-stamp field that indicates when a record was created.
type: date
- arguments:
- description: The name of the table to query
- description: The name of the table to query.
name: table_name
required: true
- defaultValue: '10'
Expand All @@ -1027,7 +1027,7 @@ script:
- defaultValue: '0'
description: Starting record index from which to begin retrieving records.
name: offset
- description: 'System parameters in the format: fieldname1=value;fieldname2=value. For example: "sysparm_display_value=true&sysparm_exclude_reference_link=True"'
- description: 'System parameters in the format: fieldname1=value;fieldname2=value. For example: "sysparm_display_value=true&sysparm_exclude_reference_link=True".'
name: system_params
description: Queries the specified table in ServiceNow.
name: servicenow-query-table
Expand Down Expand Up @@ -1135,7 +1135,7 @@ script:
description: Deletes a record in the specified ServiceNow table.
name: servicenow-delete-record
- arguments:
- description: Table name
- description: Table name.
name: table_name
required: true
description: Lists API fields for the specified ServiceNow table.
Expand Down Expand Up @@ -1452,7 +1452,7 @@ script:
description: Unique ID of the work item assigned to the queue.
type: String
- contextPath: ServiceNow.WorkItem.DocumentTable
description: Name of the table associated with the document
description: Name of the table associated with the document.
type: String
- contextPath: ServiceNow.WorkItem.DocumentID
description: Unique ID of the document to be routed to the queue.
Expand Down Expand Up @@ -1541,28 +1541,28 @@ script:
description: ServiceNow ticket close code.
type: Unknown
- arguments:
- description: ID of the change request
- description: ID of the change request.
name: id
required: true
description: gets the tasks associated to change request
description: gets the tasks associated to change request.
name: servicenow-get-tasks-for-co
outputs:
- contextPath: ServiceNow.Tasks.ID
description: Task ID
description: Task ID.
type: String
- contextPath: ServiceNow.Tasks.Description
description: Description of task
description: Description of task.
type: Unknown
- contextPath: ServiceNow.Tasks.Name
description: Name of task
description: Name of task.
type: Unknown
- contextPath: ServiceNow.Tasks.State
description: state of task
description: state of task.
type: Unknown
- arguments:
- auto: PREDEFINED
defaultValue: '0'
description: action to be performed on path
description: action to be performed on path.
isArray: true
name: method
predefined:
Expand All @@ -1571,32 +1571,32 @@ script:
- PATCH
- DELETE
required: true
- description: the API path starting with forward slash (/)
- description: the API path starting with forward slash (/).
name: path
required: true
- description: data to send in body, can be json
- description: data to send in body, can be json.
name: body
- description: json of headers to add
- description: json of headers to add.
name: headers
- auto: PREDEFINED
defaultValue: 'false'
description: Service Catalog Call
description: Service Catalog Call.
name: sc_api
predefined:
- 'true'
- 'false'
- auto: PREDEFINED
defaultValue: 'false'
description: Change Request Call
description: Change Request Call.
name: cr_api
predefined:
- 'true'
- 'false'
description: Generic call to ServiceNow api
description: Generic call to ServiceNow api.
name: servicenow-generic-api-call
outputs:
- contextPath: ServiceNow.Generic.Response
description: Generic response to servicenow api
description: Generic response to servicenow api.
type: string
dockerimage: demisto/python3:3.10.13.72123
isfetch: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ def test_get_ticket_attachments(mocker, sys_created_on, expected):
mocker.patch.object(client, 'send_request', return_value=[])

client.get_ticket_attachments('id', sys_created_on)
client.send_request.assert_called_with('attachment', 'GET', params={'sysparm_query': f'{expected}'})
client.send_request.assert_called_with('attachment', 'GET', params={'sysparm_query': f'{expected}'}, get_attachments=True)


@pytest.mark.parametrize('args,expected_ticket_fields', [
Expand Down
7 changes: 7 additions & 0 deletions Packs/ServiceNow/ReleaseNotes/2_5_40.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### ServiceNow v2

- Fixed an issue where getting attachments and the mirror-in functionality would fail when using the *v2* api version.

2 changes: 1 addition & 1 deletion Packs/ServiceNow/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ServiceNow",
"description": "Use The ServiceNow IT Service Management (ITSM) solution to modernize the way you manage and deliver services to your users.",
"support": "xsoar",
"currentVersion": "2.5.39",
"currentVersion": "2.5.40",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit bfe715f

Please sign in to comment.