Skip to content

Instantly share code, notes, and snippets.

@cryptomail
Last active August 18, 2023 23:55
Show Gist options
  • Save cryptomail/bcce855da37f8d48185375ca413d5e58 to your computer and use it in GitHub Desktop.
Save cryptomail/bcce855da37f8d48185375ca413d5e58 to your computer and use it in GitHub Desktop.
Using ZenPy to pre-create users and then submit ticket with those users.
# Zenpy accepts an API token
# Or a password
import pdb;
import sys;
#os.environ["ZENPY_FORCE_NETLOC"]
creds = {
'email' : 'email',
'password' : 'password',
'subdomain': 'subdomain'
}
# Import the Zenpy Class
from zenpy import Zenpy
from zenpy.lib.api_objects import Ticket, User
# Default
zenpy_client = Zenpy(**creds)
# instantiating Zendesk User (zenpy.lib.api_objects.User) object with name and email entered by client
zendesk_user_obj = User(
name='Joshua Teitlebaum z3nmail' + sys.argv[1],
email= sys.argv[1] + '_joshuat@z3nmail.com',
verified=True
)
# Here is where create_or_update is used and appears to be erroring (it seems to be creating a new user in Zendesk and assigning them a blank email, even though a user with that email account already exists)
zendesk_user_obj = zenpy_client.users.create_or_update(zendesk_user_obj )
# Then a ticket is created, and this user is added as the requester/submitter
zendesk_ticket = Ticket()
# Set the ticket requester and submitter ID exclusively, do NOT send the whole objects requester submitter
zendesk_ticket.requester_id = zendesk_user_obj.id
zendesk_ticket.submitter_id = zendesk_user_obj.id
# more fields entered for the ticket such as subject, comment, custom fields. Ticket created at the end
zendesk_ticket.description="something is wrong" + sys.argv[1]
zendesk_ticket.subject=sys.argv[1] + "_something is wrong"
response = zenpy_client.tickets.create(zendesk_ticket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment