Пример #1
0

################################################################
## ORGANIZATIONS
################################################################

# List
zendesk.list_organizations()

# Create
new_org = {
    'organization': {
        'name': 'Starbucks Corp'
    }
}
org_url = zendesk.create_organization(data=new_org)
org_id = get_id_from_url(org_url)

# Show
zendesk.show_organization(organization_id=org_id)

# Delete
zendesk.delete_organization(organization_id=org_id)


################################################################
## USERS (AGENTS)
################################################################

# List
zendesk.list_users()
Пример #2
0
################################################################
## ORGANIZATIONS
################################################################

# List
zendesk.list_organizations()

# Create
new_org = {
    'organization': {
        'name': 'Starbucks Corp',
        'external_id': 'crm_abc123'
    }
}
org_url = zendesk.create_organization(data=new_org)
org_id = get_id_from_url(org_url)

# Search by External ID
zendesk.search_organizations(external_id='crm_abc123')

# Show
zendesk.show_organization(organization_id=org_id)

# Show Many
zendesk.show_many_organizations(external_ids='crm_abc,crm_123')

# Delete
zendesk.delete_organization(organization_id=org_id)

Пример #3
0
zendesk.show_ticket(ticket_id=ticket_id)

# Delete
zendesk.delete_ticket(ticket_id=ticket_id)

################################################################
## ORGANIZATIONS
################################################################

# List
zendesk.list_organizations()

# Create
new_org = {'organization': {'name': 'Starbucks Corp'}}
post_data = Zendesk.dict2xml(new_org)
org_url = zendesk.create_organization(xml_data=post_data)
org_id = get_id_from_url(org_url)

# Show
zendesk.show_organization(organization_id=org_id)

# Delete
zendesk.delete_organization(organization_id=org_id)

################################################################
## USERS (AGENTS)
################################################################

# List
zendesk.list_users()
Пример #4
0
################################################################
## ORGANIZATIONS
################################################################

# List
zendesk.list_organizations()

# Create
new_org = {
    'organization': {
        'name': 'Starbucks Corp'
    }
}
post_data = Zendesk.dict2xml(new_org)
org_url = zendesk.create_organization(xml_data=post_data)
org_id = get_id_from_url(org_url)

# Show
zendesk.show_organization(organization_id=org_id)

# Delete
zendesk.delete_organization(organization_id=org_id)


################################################################
## USERS (AGENTS)
################################################################

# List
zendesk.list_users()
Пример #5
0
class ZendeskTask(object):

	_username 	= ""
	_url 		= ""
	_password 	= ""
	_token 		= ""
	_headers	= {}

	def __init__(self, url, username, password, token):
		self._username = username
		self._password = password
		self._url = url
		self._token = token
		self._zd = Zendesk(self._url, self._username, self._password, self._token, api_version=2)
		self._headers = {'content-type': 'application/json'}

	def search_by_email(self, email):
		return self._zd.search_user(query=email)

	def get_all_organizations(self):
		zen_orgs = []
		runLoop = True
		page = 1

		while runLoop:		
			results = self._zd.list_organizations(page=page)

			if int(results['count']) > 0:
				for org in results['organizations']:
					zen_orgs.append(org)
				page+=1
			if results['next_page'] is None:
				runLoop = False

		return zen_orgs

	def update_organization(self, orgId, data):
		return self._zd.update_organization(organization_id=orgId, data=data)

	def update_organization_v2(self, orgId, data):
		# Use requests module instead
		username = self._username + '/token'
		url = '{0}/api/v2/organizations/{1}.json'.format(self._url, orgId)
		r = requests.put(url, auth=(username, self._password), headers=self._headers, data=json.dumps(data))
		return r.content

	def create_organization(self, data):
		return self._zd.create_organization(data=data)

	def create_organization_v2(self, data):
		# Use requests module instead
		username = self._username + '/token'
		url = '{0}/api/v2/organizations.json'.format(self._url)
		r = requests.post(url, auth=(username, self._password), headers=self._headers, data=json.dumps(data))
		return r.content
	
	def update_user(self, userId, data):
		return self._zd.update_user(user_id=userId, data=data)

	def list_organization_fields(self):
		r = self._zd.list_organization_fields()
		return { "count" : r['count'], "fields" : r['organization_fields'] }

	def search_organization_by_name(self, name):
		return self._zd.autocomplete_organizations(name=name)

	def get_existing_organization_field_options(self, field_id):
		return self._zd.show_organization_field(field_id=field_id)['organization_field']['custom_field_options']

	def add_organization_field_dropdown(self, field_id, field_name='Vict0r Duan', field_value='test1'):
		# Dropdown fields need all options to be added
		existing_fields = self.get_existing_organization_field_options(field_id=field_id)

		existing_fields.append({ 'name' : field_name, 'value' : field_value })
		data = { "organization_field" : { "custom_field_options" : [{"name": "test", "value": "test2"}] }}
		try:
			print data
			print self._zd.update_organization_fields(field_id=field_id, data=data)
		except Exception, err:
			print err
			return self.get_existing_organization_field_options(field_id=field_id)

		return self.get_existing_organization_field_options(field_id=field_id)