- Run Exchange Online commands using Azure Automation - Tue, Jul 25 2023
- Connect to Exchange Online with PowerShell and certificate-based authentication - Wed, Jul 19 2023
- Office Deployment Tool (ODT): Deploy Office using custom XML files - Thu, Mar 30 2023
The first thing you will need to know is that to use what I will term custom APIs in Power Automate, you need the use of an HTTP action; this is a premium feature of Power Automate and requires a license after the first 100 days.
The Zendesk API documentation is based on Curl and Postman, which are common tools for accessing and testing APIs. Converting those examples to PowerShell or Power Automate is not always straightforward.
To access the API, you require a specific URL and a JSON-formatted HTTP Body. Before you begin, be sure to create an API key in Zendesk. My process uses API tokens, but other authentication providers, such as OAuth, are available.
Each action is sent to a specific URL within the API endpoint. The base URL for that is usually https://mycompany.zendesk.com/api/v2. Then we add a path based on the action we are taking.
Creating a new Zendesk ticket
The easiest action to take is to create a new ticket. In Power Automate, add an HTTP Action. The method should be POST, as we are POSTING information to the API. The URL will be our base URL with /tickets.json appended.
Then, we need to format our body. A basic new ticket body looks like this:
{ "ticket": { "subject": , "requester": , "comment": { "public": "true", "html_body": }, "tags": "" }
In the example, you can see how it appears in Power Automate with the addition of a subject (from a variable) and the requester address; the HTML body is the body of a received email.
The last thing to include is the header. This must be included in all your HTTP requests, as it will authenticate you to Zendesk. Each API you work with will have different requirements for authentication.
Zendesk requires you to provide your username and API key as a base64-encoded string. You can store this in a variable and use it in your header section.
Now, if we submit our flow, a new ticket will be opened.
Of course, this is the most basic example I can provide. The ticket body can be highly customized based on your Zendesk environment and include variables from the flow you are running.
Creating a ticket comment
Adding a comment to an existing ticket can be just as useful. Rather than forwarding an email to Zendesk and having a second ticket created, we can post a comment on our original ticket.
To post a comment on a ticket, you need to know the ticket ID. Writing about how to use the Search API would probably take up an entire article, so I won't go into that here. Suffice to say, if you know the ticket ID, you can put in a comment.
Our URL now looks like this: https://mycompany.zendesk.com/api/v2/tickets/ticketID.json
And this is our JSON body:
{ "ticket": { "comment": { "html_body": "A ticket update message", "public": "false" } } }
Setting "public" to true or false makes the comment internal (private) or public. Our method is now PUT.
Attaching a file in Zendesk
Attaching files to tickets is more complicated than you might first think. It is a two-stage process. You first upload the file and receive a token. You then include that token in your ticket body to complete the attachment.
Uploading the file requires converting the content of the file to base64/binary. Luckily, Power Automate includes an expression for that. In my example, I am uploading a file attached to an email, which could be a log file or a PDF report.
The expression in the 'base64ToBinary Attachment Content' action is:
base64toBinary(items('Attachment_To_Ticket')?['contentBytes'])
With the Uploads endpoint, we do not provide a JSON body; we simply provide the bytes of the file.
Our URL becomes:
https://mycompany.zendesk.com/api/v2/uploads.json?filename="my filename.doc"
Our method becomes POST, and our body is the output of our bas64ToBinary conversion.
When this action is triggered, the response body contains our token.
Using a Parse JSON action, we can parse the body response from our Upload File action and extract our file token.
In this image, you can see how the token becomes part of our dynamic content, which we then store in a variable.
We can then include that token in our JSON body for either a comment or a new ticket.
Conclusion
This article covered just a brief example of how you can work with the Zendesk API in Power Automate. Of course, we only scratched the surface of the Zendesk API possibilities. With the help of the examples and the API documentation, you should be able to automate all aspects of Zendesk with Power Automate.
Zendesk, in fact, has its own connector published, but it does not yet expose all the activities you may wish to use.
Subscribe to 4sysops newsletter!
Using custom connectors, you can even create your own API-based tools. For example, I recently created an Azure function that I can access using Microsoft's Azure API service. This is now tied to my own production flows.
Hi Robert,
I am receiving the following error:
{"error":"Couldn't authenticate you"}
When i check headers appears: ""Authorization:": "Basic xxxxx" not sanitized.
Could you help me please?
Need to confirm your API Key – the key you get from ZenDesk needs to be converted to base64 along with your token, which is usually your ZenDesk "userID/token" (including /token) then a colon, then your api key.
userid/token:apikey <– convert this to base64
Hi Robert,
Would it be possible to pass attachments that are from a Microsoft form or Sharepoint item? I am having trouble when I get to the base64ToBinary function.
Thank you!
You need to check if the content when retrieved from sharepoint is already in base64 or if it needs to be converted.
Hi Robert,
Great article can you close tickets also via power automate to ZenDesk?
Yes you can perform many actions, including close, merge etc.
Hello Robert,
Very helpful article. I am trying to get the attachment to zendesk part working. Can you clarify where you are getting the attachment output from in the ‘Attachment to Ticket’ section.
Thanks in Advance!
Attaching a file is a two step process.
First you must POST an HTTP request with the Base64 content of the file as the body. This is in screen shot ‘Upload attachment action’
That HTTP request, response should be parsed with JSON. ‘Parsing the JSON file’ you will need to run this once so you can get the JSON Schema, once you have that you will be able to get the Attachment Token, ‘Upload a file in the ticket body’ which you can store in a variable if you want.
Hello Robert,
This works fantastic with 1 attachment. I am running into an issue with a list item with multiple attachments. Any advice would be greatly appreciated!!
Honestly, I don’t know the solution but I haven’t tried to do multiple attachments.
Are you able to upload each attachment and collect the token, because it should then be a matter of linking the tokens to the comment, by adding the token to the uploads section.
You may need to make that an array rather than a string and then append each token to it.
I’m grabbing my attachment from a list item and when I append it to the AttachmentArray variable I’m trying to convert it to using the following:
When I start my expression with base64toBinary and add my Attachment Content it auto formats to: base64ToBinary(outputs(‘Get_attachment_content’)?[‘body’])
I then get this error:
Unable to process template language expressions in action ‘Append_to_array_variable’ inputs at line ‘0’ and column ‘0’: ‘The template language function ‘base64ToBinary’ expects its parameter to be a string. The provided value is of type ‘Object’. Please see https://aka.ms/logicexpressions#base64ToBinary for usage details.’.
Does this actually produce the expected result? (ie, a string)
base64ToBinary(outputs(‘Get_attachment_content’)?[‘body’])
The error says it is an object not a string, so if you put this into a ‘compose’ data operation, what does it show you?
Here’s a video of what I’m encountering. Thought this might be easier! https://drive.google.com/file/d/1wQUZm5EX8PCC3Ud_ioC4Z9f0gpusNjGN/view?usp=sharing
Thanks for the detailed article, this really helped me out! Just wanted to note that you are missing a closing curly-bracket in the copied text template. It believe it should be:
——————
Hi Robert,
I am trying to use power automate with Zendesk and Planner. We are trying to create a ticket in Zendesk when a Planner Task is added in Planner in our teams. I am trying to set the Ticket Type as a Task as it comes in. But it dose not update. I have included the View code portion from the Code preview in power automate. I am very new with both Zen and power Automate, but I am really enjoying it. Any help you could give would be great. Cheers
For those not realizing the “Basic” needs to have a space after it (like me), before your base 64 encoded string in the format: email@mydomain.com/token:mytoken, please note it should have a SPACE afterwards.