Zendesk is a popular customer service solution, and Power Automate enables creating automated workflows. In this article, I will explain how to access the Zendesk API from Power Automate. In particular, I will demonstrate how to attach files, create new tickets, and add ticket comments in Zendesk with Power Automate.

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": ""
}
The JSON ticket body

The JSON ticket body

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.

Zendesk API authorization

Zendesk API authorization

Now, if we submit our flow, a new ticket will be opened.

Creating a new Zendesk ticket

Creating a new Zendesk ticket

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.

Creating a JSON ticket comment

Creating a JSON ticket comment

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.

A flow for uploading an attachment

A flow for uploading an attachment

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.

Upload attachment action

Upload attachment action

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.

Parsing the JSON file

Parsing the JSON file

In this image, you can see how the token becomes part of our dynamic content, which we then store in a variable.

An attachment token

An attachment token

We can then include that token in our JSON body for either a comment or a new ticket.

Upload a file in the ticket body

Upload a file in the ticket body

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.

Power Automate Connectors

Power Automate Connectors

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!

Regex Custom Connector

Regex Custom Connector

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.

0
6 Comments
  1. Elkin Reyes 5 months ago

    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?

    0

    • Author

      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

      +1

  2. Cullen Cammack 4 months ago

    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!

    0

    • Author

      You need to check if the content when retrieved from sharepoint is already in base64 or if it needs to be converted.

      0

  3. Peter Wilcox 3 months ago

    Hi Robert,

     

    Great article can you close tickets also via power automate to ZenDesk?

    0

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account