open zendesk ticket in python

To open a Zendesk ticket in Python, you will need to use the Zendesk API. Here's an example using the requests library:

main.py
import requests
import json

zendesk_url = 'https://{subdomain}.zendesk.com/api/v2/tickets.json'
user = '{email}/token'
api_token = '{api_token}'

headers = {
    'Content-Type': 'application/json'
}

data = {
    'ticket': {
        'subject': 'Example Subject',
        'comment': {
            'body': 'Example comment'
        },
        'requester': {
            'email': 'example@example.com'
        },
        'priority': 'normal'
    }
}

response = requests.post(
    zendesk_url.format(subdomain='your-subdomain'),
    headers=headers,
    auth=(user.format(email='your-email'), api_token),
    data=json.dumps(data)
)

print(response.status_code)
660 chars
33 lines

This code will create a new ticket in Zendesk with the subject "Example Subject" and the comment "Example comment". You will need to replace {subdomain}, {email} and {api_token} with your own Zendesk subdomain, email and API token respectively.

gistlibby LogSnag