Using Powershell to operate cURL to create tickets.

Answered


Posted Apr 22, 2022

I'm biggest on Powershell working in Windows and looping through spreadsheets perform mundane tasks.  Loading info to SQL, sending emails, etc.

"Powershell" didn't return much in the Zendesk community support so when I hit this combination that functioned, maybe it's of use to you.

 

This line ran through a Powershell ISE -

curl.exe https://myZen.zendesk.com/api/v2/tickets.json -d "@\\my\path\to\the\JSON\text.file" -u "myEmail@myDomain.com/token:1a2b3c4d5e6f7g8h9i0kMyToken" -X POST -H "Content-Type:Application/JSON"


Where \\my\path\to\the\JSON\text.file  contains the JSON built from parsing a spreadsheet with the appropriate fields - 


<
{
"ticket": {
    "requestor": {"name": "YourName Here"},
    "email": "myEmail@myDomain.com",
    "submitter_id": 12345678986754321,
    "subject": "My ticket created by a Powershell cURL execution.",
    "comment": {"body": "Created this ticket"},
    "assignee_email": "myEmail@myDomain.com",
    "status":"hold",
"custom_fields":[{"id":1500004819162,"value":"Recurring"},
{"id":1500012399961,"value":"Normal"}]
}
}
>

Where we created the custom fields representing a ticket type and severity value.

 

This darn thing created tickets for me.


0

1

1 comment

 What happens if you change the curl from a POST to a GET? That should return a list of tickets instead of creating one: 
https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#list-tickets

One trick I like for these tasks is to throw the GET url into a Firefox browser where you are signed into Zendesk, ie. "https://{yourdomain}.zendesk.com/api/v2/tickets/". Firefox has a built in JSON prettify setting, that makes it really easy to see how the data is set up and what the field names are, without having to copy/paste over to something like VisualStudio. I use it a lot to do a similar task with parsing ticket data in Python. 

1


Sign in to leave a comment.

Didn't find what you're looking for?

New post