Recent searches
No recent searches
End point request: Delete all custom object records
Posted Nov 17, 2023
Similar to the interface feature request described in this post, it would be helpful if the custom object records endpoint had a bulk delete feature. In short, I would like to delete all of my custom object's records due to a schema adjustment (we are changing the convention of our external-ID nomenclature and all of the records need to be replaced).
Additionally, we will be exploring ways of managing bulk record updates and being able to drop all of the records would simplify the demand on the Zendesk custom objects API. Unfortunately, using the existing bulk functionality requires a list of IDs to delete - we want to delete everything and even if we gathered the list, it would exceed the pagination limits.
Creating something akin to a stored procedure would simplify and unburden usage of both client and Zendesk APIs.
1
5 comments
Vj Gunawardana
Hi mfg - could you just delete the object itself? That should delete all records but the drawback is that you can't reuse the same key.
0
mfg
Hi Vj Gunawardana ,
I want to be able to refresh the data. Deleting the object and then replicating but with a different key would cause all connections/references to the original key to break.
0
Greg Katechis
Hi mfg! I see that you created some feedback that has been reviewed by our product team, which is exactly the path to take for this! Due to the similarity of the requests, I would recommend commenting in that same post you created and if Shawna needs more details, she can let you know there!
0
Edward Mitchell
I ran into the same issue so I ended up creating a bit of python code to deal with it. This loops through every id from 0-199 and submits an api call to delete it. Even if it fails, it goes on to the next one. This worked for me, hope it helps someone else.
1
Yoram
Unfortunately, I didn't add an external id to the records and I I wanted to delete all of the records and import them back correctly.
Based on Edward's script, I created the following Python script that deletes the records from the object based on a defined number of records to delete.
There are. some debugging options in case you will need them.
api_name = '<emailname@emaildomain.com>/token'
api_key = '<API Token Key>'
zendesk_baseurl = 'https://<sub_domain>.zendesk.com'
object_name = '<object key>'
# Create credentials for API
credentials = api_name, api_key
session = requests.Session()
session.auth = credentials
try:
# Fetch records from the custom object
per_page = 100 # Adjust per_page as needed
total_records_to_delete = 1000 # Adjust the number of records to delete
records_deleted = 0
while records_deleted < total_records_to_delete:
url = f'{zendesk_baseurl}/api/v2/custom_objects/{object_name}/records.json?per_page={per_page}'
response = session.get(url)
response.raise_for_status()
records = response.json().get('custom_object_records', [])
# If there are no records, break the loop
if not records:
break
# Delete each record
for record in records:
if records_deleted >= total_records_to_delete:
break
record_id = record['id']
delete_url = f'{zendesk_baseurl}/api/v2/custom_objects/{object_name}/records/{record_id}.json'
delete_response = session.delete(delete_url)
delete_response.raise_for_status()
print(f"Deleted record with ID: {record_id}")
records_deleted += 1
except requests.exceptions.HTTPError as e:
print(f"HTTP error occurred: {e.response.status_code} {e.response.reason}")
print(f"Response content: {e.response.text}")
except Exception as e:
print(f"An error occurred: {e}")
I whish this option would be a part of the Zendesk UI option.
0