How to delete all webhooks in bulk?
There is an api end point to delete webbooks one by one.. any end point to delete all in once?
Answers
-
Hi @Sunil Patel
You're correct, deleting webhooks (see here) is not one of the supported bulk operations; you would need to write a script to loop through them all.
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
-
Here is a python script to loop through and delete all inactive webhooks. If you want to delete all active webhooks, change the line if j['data'][x]['enabled'] == False: to if j['data'][x]['enabled'] == True:
If you want to delete both inactive and active webhooks, take out that line all together.
Is it well written? Probably not. But it gets the job done.
Note: the 'whArray' will print twice. One will the IDs of all inactive webhooks. The second time should print blank if successful. This will also create a file titled 'SSwebhookdata.json' that contains all the data for the webhooks. Was this necessary? Probably not but it's the only thing I could get to work.
Anywho, enjoy.
import smartsheet import requests import json smartsheet_client = smartsheet.Smartsheet('SMARTSHEET TOKEN HERE') IndexResult = smartsheet_client.Webhooks.list_webhooks( page_size=100, page=1, include_all=False) results = str(IndexResult) response = json.loads(results) with open('SSwebhookdata.json', 'w') as f: json.dump(response, f) with open('SSwebhookdata.json', 'r') as string: my_dict=json.load(string) string.close() j = my_dict x = -1 indexArray = [] whArray = [] for each in j['data']: x += 1 indexArray.append(x) for x in indexArray: if j['data'][x]['enabled'] == False: whArray.append(j['data'][x]['id']) print(whArray) def deleteWH(): smartsheet_client.Webhooks.delete_webhook() for each in whArray: smartsheet_client.Webhooks.delete_webhook(each) print(whArray) print(IndexResult)
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 139 Industry Talk
- 472 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 496 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives