The liquid script is a simple scripting language developed by Shopify, that is used throughout Zendesk - You can use it in tickets, macros, triggers, webhook URLs, and many other places!
The liquid script gives you the ability to perform a more advanced conditional logic where needed. This can be especially useful for setting up workflows with our app, as it gives you the ability to:
- Conditionally show different content in approval emails, based on any number of parameters
- Conditionally add different approvers / create different child tickets from a single trigger, instead of having to set up multiple triggers
Zendesk placeholders
Almost always, you will want to use values from the Zendesk Tickets in combination with the liquid script. That way, you are able to "ask" different questions, such as - If the form that the user has used is HR form - Then let's do this.
How do we access that form data? Using Zendesk placeholders! Zendesk placeholders allow you to reference almost any data from ticket forms, requesters, or assignees' profiles.
Basics
As you can see in the documentation for liquid scripts, there are a lot of different statements you can use. One of the most common statements that we see people using, that we will cover today, are conditional statements.
Of course, depending on your workflow, you might need to use different statements to achieve a different result.
In our case, we want to create a liquid code that will print out "User has used the HR form" if the ticket is submitted using the HR form. In all of the other cases, we want to print out "It's some other form". To do this with the liquid script, we can use:
{%- if ticket.ticket_form == 'HR form' -%}
User has used the HR form
{%- endif -%}
Let's expand this to add the part that will print out "It's some other form" for the other forms:
{%- if ticket.ticket_form == 'HR form' -%}
User has used the HR form
{%- else -%}
It's some other form
{%- endif -%}
There we go, we got our first conditional statement working!
Using liquid in Zendesk Triggers
When you want to send a message to a webhook, Zendesk allows you to use the liquid script!
To expand on the example above, let's say you want to add approver A when the ticket is using HR form, and approver B when the ticket is not using it.
You have an option of creating two different triggers, but you can also create a single trigger and use the liquid script like this:
Few things to keep in mind:
- You might have seen by now that all of our liquid has a - that is not always there in the official documentation. Places where you open up the bracket - {%- and where you close it -%}. The - is there to remove any empty space that would be printed otherwise. Without that, you might see your triggers not working as expected, because they are sending empty spaces that are encoded in a different way than what you might have expected.
- Zendesk might show you validation errors, for a perfectly good liquid script:
This doesn't have to mean your liquid is not good. Zendesk's validation engine was made to validate JSON, not to validate the liquid script. Because of that, you might get false positives. The best thing to do is to test your liquid script, which is covered in the next part.
Testing & Troubleshooting
As mentioned above, Zendesk supports liquid script almost everywhere. Because of that, the easiest way to test your liquid - Is to paste it directly into a comment of a ticket, and see the result. That way, you will know exactly how will Zendesk interpret the liquid script for a given ticket, and what data is sent to the servers for that liquid script.