Closed guin0x closed 11 months ago
This issue is being tracked internally at https://jira-hq.paloaltonetworks.local/browse/CIAC-8348. We'll post an update here once it's handled.
Hey @guin0x the issue fixed, can you please confirm?
I'm still facing the same issue. Maybe I'm doing something wrong?
I'm still doing the same as I mentioned before, and I get the same error (TypeError: a bytes-like object is required, not 'str')
in the last line api_instance.download_file(entryid = incidents_csv)
.
Below the entire code.
import demisto_client.demisto_api
from demisto_client.demisto_api.rest import ApiException
from pprint import pprint
api_key = 'XXX'
base_url = 'XXX'
api_instance = demisto_client.configure(base_url=base_url, api_key=api_key, verify_ssl=False)
filter = demisto_client.demisto_api.SearchIncidentsData()
inc_filter = demisto_client.demisto_api.IncidentFilter()
inc_filter.query='status: Active'
filter.filter = inc_filter
update_data_batch = demisto_client.demisto_api.UpdateDataBatch()
update_data_batch.filter = inc_filter
incidents_csv = api_instance.export_incidents_to_csv_batch(update_data_batch = update_data_batch)
api_instance.download_file(entryid = incidents_csv)
@guin0x Hey
Please update the demisto-py
version to the latest (3.2.12)
And test the following code:
import demisto_client.demisto_api
host = '<your host>'
api_key = '<your api-key>'
api_instance = demisto_client.configure(base_url=host, api_key=api_key)
inc_filter = demisto_client.demisto_api.IncidentFilter()
inc_filter.query = 'status: "Active"'
update_data_batch = demisto_client.demisto_api.UpdateDataBatch(filter=inc_filter, all=True, columns=['id', 'name', 'status'])
api_response = api_instance.export_incidents_to_csv_batch(update_data_batch=update_data_batch)
print(api_response)
hi @MosheEichler,
I upgraded demisto-py
to 3.2.12 and the issue seems to be resolved.
Please note that, originally, running the code you proposed in your previous answer wouldn't raise any errors since the error was related to the download_file()
function, and not with the export_incidents_to_csv_batch()
.
Nonetheless, now no error was raised. Thank you :)
I'm wondering though, for example, in your example above, api_response
would be the name of a .csv
file; then I'm trying to use the download_file()
function to download that .csv
file, but then if I try:
api_instance.download_file(entryid = api_response)
, I get something like /tmp/tmpdxj6q24x
did I misunderstand how to use download_file() and export_incidents_to_csv_batch()?
The download_file
function does not expect a file name as a parameter, but an etryId, which can be found in the warroom
For example:
ahh... great, thanks a lot! I still have a few questions I'll park them here:
1) How can I download the .csv
that was exported with export_incidents_to_csv_batch()
?
2) If I use the download_file()
to download some incident that I got the ID from the war room, I still get as an output some path so some tmp;
3) I have also tried using the get_incident_as_csv
but it didn't work..
So far, the best solution to download all the incidents is with search_incidents
and then write it to some file, I'm just trying to find any alternative to download a bunch of incidents, that's why I started looking into the download_file
function.. could you maybe point me somewhere I can find this info?
Thank you.
Hey @guin0x
export_incidents_to_csv_batch()
just export the incidents to a csv file in order to download this file to your computer you should use the get_incident_as_csv()
function.
something like this:
import demisto_client
api_key =
api_instance = demisto_client.configure(base_url=host, api_key=api_key) inc_filter = demisto_client.demisto_api.IncidentFilter() inc_filter.query = 'status: "Active"'
update_data_batch = demisto_client.demisto_api.UpdateDataBatch(filter=inc_filter, all=True, columns=['id', 'name', 'status'])
csv_id = api_instance.export_incidents_to_csv_batch(update_data_batch=update_data_batch) api_response = api_instance.get_incident_as_csv(csv_id) print(api_response) # this is the path to the downloaded file on your computer.
2. The `download_file()` function is not related to an incident, this function is for downloading files form the war room to your computer by giving the **`entry_id`** of the file.
3. See the example above how I used the function it works for me.
Please contact your customer success representative if you have any further questions
Description
When using the
api_instance.download_file()
function I get the following error: TypeError: a bytes-like object is required, not 'str'However, according to the docs, the input of
download_file
should be a string.The full error trace is:
To Reproduce Steps to reproduce the behavior:
Expected behavior I would expect to download the
.csv
file with the incidents I want.