Recent searches


No recent searches

Create User Account From Ticket

Answered


Posted Jan 26, 2022

Hi All,

 

I've been given a challenge and was wondering if it were at all possible.

A user would create a ticket requesting a Zendesk agent account for themselves to be created.  This would go to an approval team, once approved, an account is created using details entered into the ticket.

I have no idea where to start but figured i would start by asking if it were even possible using Zendesk workflow alone.


0

4

4 comments

image avatar

Cheeny Aban

Zendesk Customer Care

Hi Morris, 

When you receive an email at one of your support addresses, Support automatically creates a user record if one does not exist already. Unfortunately, there is no option to prevent that actions since it is hardcoded in the system. Here's are the other ways how a user can be created in Zendesk

0


This is definitely possible, it's how I do onboarding but it is very complicated and cannot be done with just Zendesk. It really requires knowledge of webhooks, the zendesk API and Python, so for most admins and smaller-sized accounts this is not really going to be worth the effort, but if you're working on an Enterprise instance and need to onboard hundreds or even thousands of agents, this works well for me.

I use Zapier and send it the information I need from Zendesk via a webhook using a "catch webhook" task in Zapier. What I ask for in the Zendesk form is the new agent's name, their email, and because we're such a large company with so many employees I ask for the email of an agent who has the same permissions and group memberships that they would like for the new agent. I have an approved onboard form that is only available to me and when I solve an approved onboard ticket, the webhook fires and sends the info to Zapier. Zapier catches the webhook and runs (something like) this python code:

*this code is just cleaned up to remove my personal info/creds, there's definitely still a lot of redundant definitions and print statements that were just used in testing and never cleaned up because I'm lazy and that's why I automate stuff lol

import requests
import json

# Zapier Data will be packaged like this:
# input_data = {
# 'email': 'new_agent@yourdomain.com',
# 'name': '{{New Agent Name}}',
# 'alias': '{{New Agent Alias}}',
# 'cloned_agent_email': 'cloned_agent@yourdomain.com'
# }

email = input_data['email']
name = input_data['name']
try:
alias = input_data['alias']
except:
alias = name
cloned_agent_email = input_data['cloned_agent_email']



url = 'https://yourdomain.zendesk.com/api/v2/users/search.json?query=' + cloned_agent_email
user = 'your_email@yourdomain.com' + '/token'
pwd = 'YOURAPIKEY'
response = requests.get(url, auth=(user, pwd))
data = response.json()
cloned_agent = data['users'][0]
cloned_agent_id = cloned_agent['id']
custom_role_id = cloned_agent['custom_role_id']
agent_role = cloned_agent['user_fields']['agent_role']
default_group_id = cloned_agent['default_group_id']

#Check if Exists
url = 'https://yourdomain.zendesk.com/api/v2/users/search.json?query=' + email
user = 'your_email@yourdomain.com' + '/token'
response = requests.get(url, auth=(user, pwd))
data = response.json()
print("line 464" + str(data))

if data['count'] == 0:
print("no existen")
exists = 0
elif data['count'] == 1:
new_user = data['users'][0]
new_user_id = new_user['id']
print(new_user_id)
print("new user id: " + str(new_user_id))
print(type(new_user))
exists = 1
else:
print(type(data['users'][0]))
print()

data = json.dumps({
"user": {
"custom_role_id": custom_role_id,
"email": email,
"name": name,
"role": "agent",
"default_group_id": default_group_id
}
})

if exists == 1:
url = 'https://yourdomain.zendesk.com/api/v2/users/' + str(new_user_id)
print(url)
user = 'your_email@yourdomain.com' + '/token'
headers = {'Content-Type': 'application/json'}
response = requests.put(url, data=data, headers=headers, auth=(user, pwd))
new_user = response.json()
print(response.text)
new_user_id = new_user['user']['id']
exists = 1

elif exists == 0:
url = 'https://yourdomain.zendesk.com/api/v2/users/'
user = 'your_email@yourdomain.com' + '/token'
headers = {'Content-Type': 'application/json'}
response = requests.post(url, data=data, headers=headers, auth=(user, pwd))
new_user = response.json()
print("like 495: " + str(new_user))
try:
new_user_id = new_user['user']['id']
except:
exit()
else:
print("boolean messed up")

print("user creation JSON response: " + str(response.json))

print(new_user)

print("new user id: " + str(new_user_id))

# CLONE GROUP MEMBERSHIPS
url = 'https://yourdomain.zendesk.com/api/v2/users/' + str(cloned_agent_id) + '/group_memberships.json'
user = 'your_email@yourdomain.com' + '/token'
headers = {'Content-Type': 'application/json'}
response = requests.get(url, headers=headers, auth=(user, pwd))
data = response.json()
group_memberships = data['group_memberships']
for i in range(0, len(group_memberships)):
url = 'https://yourdomain.zendesk.com/api/v2/group_memberships'
group_id = group_memberships[i]['group_id']
data = json.dumps({
"group_membership": {
'group_id': group_id,
'user_id': new_user_id
}
})
response = requests.post(url, data=data, headers=headers, auth=(user, pwd))
print(response.text)

If you're a smaller company, you can ask for all sorts of custom user attributes on the form rather than cloning an agent, and just have a bunch of if statements like

if input_data[User Department] == 'sales':
     department = 'sales'

And then add 

"user_fields": {
"agent_department": department
}

to your update ticket payload.

2


Hi Dan,

 

That\s a great solution thank you. We are running an Enterprise level instance here and use Zapier as well as having in house python expertise so this will work perfectly for us. 

Thank you again for your detailed solution, very much appreciated.

1


Morris Coyle no prob, glad to get to show this off lol

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post