facetoe / zenpy

Python wrapper for the Zendesk API
GNU General Public License v3.0
342 stars 161 forks source link

Bug while deleting multiple organizations #659

Open umazhar-cond opened 3 days ago

umazhar-cond commented 3 days ago

I am getting a below bug while deleting multiple organizations using external ids. I have already cross verified my list of external ids which don't contain None. This is how I am invoking the delete function,

zenpy_client.organizations.delete(orgs_api_objects, destroy_many_external=True)

Bug: Traceback (most recent call last): File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/api.py", line 388, in _check_response _json = response.json() File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/requests/models.py", line 910, in json return complexjson.loads(self.text, **kwargs) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/simplejson/init.py", line 514, in loads return _default_decoder.decode(s) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/simplejson/decoder.py", line 386, in decode obj, end = self.raw_decode(s) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/simplejson/decoder.py", line 416, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.errors.JSONDecodeError: Invalid \X escape sequence '\': line 4 column 102 (char 150)

Traceback (most recent call last): File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/app/sf.py", line 189, in main() File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/app/sf.py", line 162, in main create_organization(zenpy_client, accounts, batch_size) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/app/sf.py", line 145, in create_organization status = zenpy_client.organizations.delete(orgs, destroy_many_external=destroy_ids) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/api.py", line 635, in delete return CRUDRequest(self).delete(api_objects) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/request.py", line 115, in delete response = self.api._delete(url, payload=payload) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/api.py", line 177, in _delete timeout=self.timeout) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/api.py", line 227, in _call_api self._check_response(response) File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/zenpy/lib/api.py", line 402, in _check_response response.raise_for_status() File "/Users/usamamazhar/PycharmProjects/cdp-data-lake-consumer/venv/lib/python3.7/site-packages/requests/models.py", line 953, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://(subdomain).zendesk.com/api/v2/organizations/destroy_many.json?ids=None,None,None,None,None

cryptomail commented 15 hours ago

This is very odd, as it appears that ids is being used instead of external_ids since you used the parameter destroy_many_external I will need to reproduce this and trace it.

cryptomail commented 15 hours ago

what version are you currently on @umazhar-cond

umazhar-cond commented 14 hours ago

zenpy==2.0.49

umazhar-cond commented 14 hours ago

It was strange to me as I was passing external_ids rather than ids.

cryptomail commented 14 hours ago

Yes...which is why at this point I will try to repro myself because something is bewitched and not obeying the code I seemingly have in front of me. :)

cryptomail commented 14 hours ago

I think it may be best to pass the ACTUAL objects and actual organization objects. You can see that there is an accessor expecting external_id to be ON the actual object.

            kwargs['destroy_many_external'] = [
                o.external_id for o in api_objects
            ]

is api_objects an array of Organizations?

cryptomail commented 14 hours ago

If you're passing in external_ids, it won't pass the accessor applied on o

cryptomail commented 14 hours ago

If we feel that this interface is INCORRECT and you want to fast track deletion with passing a flat array of already canonicalized external_ids, then we'll have to talk and think about that :) and make some affordance for it.