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.

16 Comments
  1. Elkin Reyes 2 years 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?

    • 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

  2. Cullen Cammack 2 years 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!

    • Author

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

  3. Peter Wilcox 2 years ago

    Hi Robert,

     

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

  4. Anant Shah 2 years ago

    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!

    • Author

      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.

  5. Anant Shah 2 years ago

    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!!

    • Author

      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.

  6. Chris Green 2 years ago

    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.’.

    • Author

      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?

  7. Chris Green 2 years ago

    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

  8. Keith Brown 1 year ago

    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:
    ——————

    {
      "ticket": {
        "subject": ,
        "requester": ,
        "comment": {
          "public": "true",
          "html_body": 
        },
        "tags": ""
        }
    }

  9. Morty Douglass 1 year ago

    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

    {"shared_zendesk"
            },
            "parameters": {
                "table": "tickets",
                "item/type": "task",
                "item/subject": "@triggerOutputs()?['body/title']",
                "item/description": "This is a Ticket from Power Automate"""}

  10. Doug Blystone 5 months ago

    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.

Leave a reply

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

*

© 4sysops 2006 - 2023

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