Sign in
agent:

Assign a Zendesk ticket to a user

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
import os import requests from requests.auth import HTTPBasicAuth # Get environment variables zendesk_base_url = f"https://{subdomain}.zendesk.com" # Credentials for Zendesk API creds = _get_creds(cred_label)['creds'] zendesk_user_name = creds['username'] zendesk_api_token = creds['password'] # Get the user ID from the email url = f"{zendesk_base_url}/api/v2/users/search.json?query={user_email}" response = requests.get(url, auth=HTTPBasicAuth(f"{zendesk_user_name}/token", zendesk_api_token)) if response.status_code == 200: users = response.json().get('users', []) if users: user_id = users[0]['id'] # Assign the ticket to the user url = f"{zendesk_base_url}/api/v2/tickets/{ticket_id}.json" data = { 'ticket': { 'assignee_id': user_id } } response = requests.put(url, json=data, auth=HTTPBasicAuth(f"{zendesk_user_name}/token", zendesk_api_token)) if response.status_code == 200: print(f"Ticket {ticket_id} assigned to user {user_email} successfully.") else: print(f"Failed to assign ticket: {response.status_code} - {response.text}") else: print(f"User with email {user_email} not found.") else: print(f"Failed to retrieve user: {response.status_code} - {response.text}")
copied