KeyError due to Incorrect Dictionary Key Access in getAll Pagination of case_incident.list Method
Halfbrowse opened this issue · comments
Description
When adding the getAll=True attribute to an api call like so
opencti_client = OpenCTIApiClient(
os.getenv("OPENCTI_URL"),
os.getenv("OPENCTI_TOKEN"),
log_level=os.getenv("OPENCTI_LOG_LEVEL", "error"),
)
all_cases = client.case_incident.list(getAll=True)
this error is returned
File "/home/main.py", line 13, in list_recent_cases
all_cases = client.case_incident.list(getAll=True)
File "/home/main/main.py/venv/lib/python3.10/site-packages/pycti/entities/opencti_case_incident.py", line 533, in list
after = result["date"]["caseIncidents"]["pageInfo"]["endCursor"]
KeyError: 'date'
Heading to the line in question we see
if get_all:
final_data = []
data = self.opencti.process_multiple(result["data"]["caseIncidents"])
final_data = final_data + data
while result["data"]["caseIncidents"]["pageInfo"]["hasNextPage"]:
after = result["date"]["caseIncidents"]["pageInfo"]["endCursor"]
I believe the issue is that the variable after should be
result["data"]["caseIncidents"]["pageInfo"]["endCursor"]
not
result["date"]["caseIncidents"]["pageInfo"]["endCursor"]
I have checked several of the other entities and case_incident appears to be the only one with this error.
Environment
- OS - Hosted by Filigran
- OpenCTI version: 6.0.10
- Pycti version: 6.0.10
- Python version: 3.10.12
Reproducible Steps
Steps to create the smallest reproducible scenario:
- Created a opencti_client
opencti_client = OpenCTIApiClient(
os.getenv("OPENCTI_URL"),
os.getenv("OPENCTI_TOKEN"),
log_level=os.getenv("OPENCTI_LOG_LEVEL", "error"),
)
- Grab all case_incidents using the getAll = True
all_cases = client.case_incident.list(getAll=True)
Expected Output
That the error would not occur and all case's would be returned.
Actual Output
A KeyError
after = result["date"]["caseIncidents"]["pageInfo"]["endCursor"]
KeyError: 'date'