Created
July 22, 2025 12:45
-
-
Save fjaguero/3b6070bc465b579a3b800c5add2fffd1 to your computer and use it in GitHub Desktop.
Zendesk Trigger Search Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Zendesk Trigger Search Script | |
SETUP INSTRUCTIONS: | |
1. Make sure you have Python 3.x installed | |
2. Create a virtual environment (recommended): | |
python3 -m venv venv | |
source venv/bin/activate # On Windows: venv\Scripts\activate | |
3. Install required dependencies: | |
pip install requests | |
4. Update the configuration variables in the main() function: | |
- ZENDESK_DOMAIN: Your Zendesk subdomain (e.g., "yourcompany") | |
- ZENDESK_EMAIL: Your Zendesk email address | |
- ZENDESK_TOKEN: Your Zendesk API token | |
RUN INSTRUCTIONS: | |
1. Activate the virtual environment (if using one): | |
source venv/bin/activate # On Windows: venv\Scripts\activate | |
2. Run the script: | |
python zendesk_trigger_search.py | |
The script will: | |
- Search for all triggers containing "lang.ai" in the title (case insensitive) | |
- Display a summary of matching triggers | |
- Save full trigger data to 'lang_triggers.json' | |
""" | |
import requests | |
import json | |
from typing import List, Dict, Optional | |
class ZendeskTriggerSearch: | |
def __init__(self, domain: str, email: str, token: str): | |
""" | |
Initialize Zendesk API client | |
Args: | |
domain: Your Zendesk domain (e.g., 'yourcompany') | |
email: Your Zendesk email | |
token: Your Zendesk API token | |
""" | |
self.base_url = f"https://{domain}.zendesk.com/api/v2" | |
self.auth = (f"{email}/token", token) | |
self.headers = {"Content-Type": "application/json"} | |
def get_all_triggers(self) -> List[Dict]: | |
""" | |
Fetch all triggers from Zendesk API with pagination support | |
Returns: | |
List of all trigger dictionaries | |
""" | |
all_triggers = [] | |
url = f"{self.base_url}/triggers.json" | |
while url: | |
try: | |
response = requests.get(url, auth=self.auth, headers=self.headers) | |
response.raise_for_status() | |
data = response.json() | |
all_triggers.extend(data.get('triggers', [])) | |
# Check for next page | |
url = data.get('next_page') | |
print(f"Fetched {len(data.get('triggers', []))} triggers...") | |
except requests.exceptions.RequestException as e: | |
print(f"Error fetching triggers: {e}") | |
break | |
return all_triggers | |
def search_triggers_by_title(self, search_word: str, case_sensitive: bool = False) -> List[Dict]: | |
""" | |
Search for triggers containing a specific word in the title | |
Args: | |
search_word: Word to search for in trigger titles | |
case_sensitive: Whether search should be case sensitive | |
Returns: | |
List of matching trigger dictionaries | |
""" | |
all_triggers = self.get_all_triggers() | |
if not case_sensitive: | |
search_word = search_word.lower() | |
matching_triggers = [] | |
for trigger in all_triggers: | |
title = trigger.get('title', '') | |
if not case_sensitive: | |
title = title.lower() | |
if search_word in title: | |
matching_triggers.append(trigger) | |
return matching_triggers | |
def print_trigger_summary(self, triggers: List[Dict]): | |
"""Print a summary of found triggers""" | |
print(f"\nFound {len(triggers)} triggers containing 'lang.ai' in the title:") | |
print("=" * 60) | |
for i, trigger in enumerate(triggers, 1): | |
print(f"{i}. {trigger.get('title', 'No Title')}") | |
print(f" ID: {trigger.get('id')}") | |
print(f" Active: {trigger.get('active', 'Unknown')}") | |
print(f" Created: {trigger.get('created_at', 'Unknown')}") | |
print(f" Updated: {trigger.get('updated_at', 'Unknown')}") | |
print("-" * 40) | |
def main(): | |
# Configuration - replace with your actual credentials | |
ZENDESK_DOMAIN = "your-domain" # Just the subdomain, not the full URL | |
ZENDESK_EMAIL = "[email protected]" | |
ZENDESK_TOKEN = "your-api-token" | |
# Initialize the search client | |
client = ZendeskTriggerSearch(ZENDESK_DOMAIN, ZENDESK_EMAIL, ZENDESK_TOKEN) | |
# Search for triggers with "lang.ai" in the title (case insensitive) | |
print("Searching for triggers containing 'lang.ai' in the title...") | |
matching_triggers = client.search_triggers_by_title("lang.ai", case_sensitive=False) | |
# Print results | |
client.print_trigger_summary(matching_triggers) | |
# Optionally, save results to JSON file | |
if matching_triggers: | |
with open('lang_triggers.json', 'w') as f: | |
json.dump(matching_triggers, f, indent=2) | |
print(f"\nFull trigger data saved to 'lang_triggers.json'") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment