zenpy icon indicating copy to clipboard operation
zenpy copied to clipboard

Added support for Search Export API

Open makcyd opened this issue 2 years ago • 1 comments

Added method:

for ticket in zenpy_client.search_export(query='created>=1month', type='ticket'):
    print(ticket.id)

Similar to zenpy_client.search(), but using Search Export API

It may be handy if the limit of 1000 results is not sufficient.

Tests passed:

~# make unittest
nosetests -v --stop
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_helpcentre.TestCategoryCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_helpcentre.TestCategoryCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_helpcentre.TestCategoryCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_helpcentre.TestCategoryCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_helpcentre.TestCategoryCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_upload_with_bytes_io (test_api.test_create_update_delete_zendesk.TestAttachmentUpload) ... ok
test_upload_with_file_obj (test_api.test_create_update_delete_zendesk.TestAttachmentUpload) ... ok
test_upload_with_path_str (test_api.test_create_update_delete_zendesk.TestAttachmentUpload) ... ok
test_upload_with_pathlib_path (test_api.test_create_update_delete_zendesk.TestAttachmentUpload) ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestGroupCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestGroupCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestGroupCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestGroupCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestGroupCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestMacrosCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestMacrosCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestMacrosCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_full_objects_create (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_half_objects_create (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_delete_full_objects (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_delete_half_full_objects (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_delete_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_delete_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_delete_single_object (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_update_full_objects (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_update_half_full_objects (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_update_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_multiple_update_single_object (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_raises_multiple_update_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_raises_toomanyvaluesexception_create (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_create (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestOrganizationCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestOrganizationFieldsCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestOrganizationFieldsCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestOrganizationFieldsCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestOrganizationFieldsCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestOrganizationFieldsCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestRecipientAddressCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestRecipientAddressCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestRecipientAddressCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_full_objects_create (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_half_objects_create (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_delete_full_objects (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_delete_half_full_objects (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_delete_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_delete_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_delete_single_object (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_update_full_objects (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_update_half_full_objects (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_update_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_multiple_update_single_object (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_raises_multiple_update_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_raises_toomanyvaluesexception_create (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_create (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestTicketCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestTicketFieldCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestTicketFieldCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestTicketFieldCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestTicketFieldCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestTicketFieldCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_full_objects_create (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_half_objects_create (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_delete_full_objects (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_delete_half_full_objects (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_delete_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_delete_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_delete_single_object (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_update_full_objects (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_update_half_full_objects (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_update_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_multiple_update_single_object (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_raises_multiple_update_raises_toomanyvaluesexception (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_raises_toomanyvaluesexception_create (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_raises_zenpyexception_on_invalid_type (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_create (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.TestUserCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
Test that a single object can be created correctly. ... ok
test_single_delete_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.UserFieldsCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_single_object_creation (test_api.test_create_update_delete_zendesk.UserFieldsCreateUpdateDelete) ... ok
test_single_object_deletion (test_api.test_create_update_delete_zendesk.UserFieldsCreateUpdateDelete) ... ok
test_single_object_update (test_api.test_create_update_delete_zendesk.UserFieldsCreateUpdateDelete) ... ok
test_single_update_raises_recordnotfoundexception (test_api.test_create_update_delete_zendesk.UserFieldsCreateUpdateDelete) ... ok
Test that a single object can be created correctly. ... ok
test_search_generator_len (test_api.test_generator.TestSearchGenerator) ... ok
test_search_returns_search_result_generator (test_api.test_generator.TestSearchGenerator) ... ok
test_ticket_slice_cross_page_size_boundary (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_ticket_slice_exact_page_size_boundary (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_ticket_slice_low_bound (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_ticket_slice_lower_page_size_boundary (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_ticket_slice_on_lower_boundary (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_ticket_slice_with_page_size (test_api.test_generator.TestTicketGeneratorSlice) ... ok
test_clean_dirty (test_api.test_incremental_object_update.TestIncrementalObjectUpdate) ... ok
test_modified_attribute_serialized (test_api.test_incremental_object_update.TestIncrementalObjectUpdate) ... ok
test_new_ticket_only_serializes_id (test_api.test_incremental_object_update.TestIncrementalObjectUpdate) ... ok
test_set_dirty (test_api.test_incremental_object_update.TestIncrementalObjectUpdate) ... ok
test_chat_object_properties_implemented (test_api.test_properties.TestProperties) ... ok
test_help_centre_properties_implemented (test_api.test_properties.TestProperties) ... ok
test_zendesk_object_properties_implemented (test_api.test_properties.TestProperties) ... ok
test_proxy_dict_assign (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_clear (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_del (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_pop (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_popitem (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_update (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_wraps_list (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_dict_wraps_zenpy_object (test_api.test_proxy.TestProxyDict) ... ok
test_proxy_list_wraps_dict (test_api.test_proxy.TestProxyDict) ... ok
test_dict_access_wrapped (test_api.test_proxy.TestProxyList) ... ok
test_list_access_wrapped (test_api.test_proxy.TestProxyList) ... ok
test_list_clean_dirty (test_api.test_proxy.TestProxyList) ... ok
test_object_clean_dirty (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_access_modification (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_append (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_assign (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_clear (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_del (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_extend (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_insert (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_iter_modification (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_pop (test_api.test_proxy.TestProxyList) ... ok
test_proxy_list_remove (test_api.test_proxy.TestProxyList) ... ok
test_zenpy_object_wrapped (test_api.test_proxy.TestProxyList) ... ok
test_cache_object (test_cache.TestCacheManager) ... ok
test_remove_from_cache (test_cache.TestCacheManager) ... ok
test_cache_purge (test_cache.TestZenpyCache) ... ok
test_object_retrieval (test_cache.TestZenpyCache) ... ok
test_set_maxsize (test_cache.TestZenpyCache) ... ok
test_throws_cache_exception_on_invalid_object (test_cache.TestZenpyCache) ... ok
test_throws_cache_exception_on_none (test_cache.TestZenpyCache) ... ok

----------------------------------------------------------------------
Ran 169 tests in 1.688s

OK

makcyd avatar Jan 16 '22 18:01 makcyd

Hello, is there a reason why this feature has not been merged, yet? The search export API is very important for queries that will return more than 1000 results: https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#export-search-results

It would be nice if zenpy would support this important endpoint soon.

asmaier avatar Jun 29 '22 09:06 asmaier

Hi! As I can see, @facetoe is not very active now. Technically I could merge this request, I reviewed it a bit, but I'm not very expirienced in complex GitHub projects, so I'm not very sure to take this responsibility :)

Ptr314 avatar Aug 18 '22 07:08 Ptr314

@Ptr314 we have been using patched zenpy for nearly 6 months now, and the only drawback we've noticed so far was that for some instances Zendesk returns "Internal Server Error" for this API, but that happened regardless of how the method was used - via zenpy or directly using "requests".

Also, the other possible issue is when a large amount of tickets gets loaded using search/export method, zenpy takes large memory footprint (because all tickets get converted into large objects).

Other than that, it worked more or less well :)

makcyd avatar Aug 18 '22 13:08 makcyd

I've just merged this request. I think we need a new release? @facetoe, as I've got to know some credentials are expected fo PyPi. How the process is done? Could I do it by myself?

Ptr314 avatar Aug 18 '22 18:08 Ptr314

Ahh, found a problem. You used an f-string in generator.py, and now this string crashes CI tests prior to Python 3.6.

Ptr314 avatar Aug 18 '22 19:08 Ptr314

Fixed this, now all the tests are OK.

Ptr314 avatar Aug 18 '22 19:08 Ptr314

Hi @Ptr314, I've pushed a release. The process is pretty straightforward, just need to get you an API token and you can upload to PyPi.

facetoe avatar Aug 21 '22 11:08 facetoe