Using custom objects in triggers

Custom objects are useful in their own right because they enable you to capture and reference your unique data within Zendesk. However, you can go further and integrate your custom objects and data into your ticket triggers. Within the trigger, any custom objects that are related to tickets through a lookup relationship ticket field can be referenced in your conditions. Similarly, you can add actions that notify users related to a custom object record.

The following example continues the IT asset management scenario described in Creating custom objects. Now that you've created the custom objects, your admin wants you to create a trigger that assigns tickets to the IT group when any Software requested value is present in a ticket.

Let's assume the existence of the following exist in your account:

  • A custom object named Software
  • A ticket lookup relationship field named Requested software, that points to the Software object. The field's id is 17531702893847. In trigger conditions, custom ticket fields are specified by id rather than key: custom_field_{id}.
  • A group named IT, with an id of 15609689242263.
  • A trigger category named Assignment, with an id of 15590471937303.

Then you can use the POST /api/v2/triggers endpoint to create the requested trigger. Refer to the API Conditions reference and API Actions reference for more details about the request body. For example:

curl https://{subdomain}.zendesk.com/api/v2/triggers.json \  -H "Content-Type: application/json" -X POST \  -u {email}:{password} \  -d '{  "trigger": {    "title": "Triage Software Requests",    "category_id": "15590471937303",    "actions": [        {            "field": "group_id",            "value": "15609689242263"        }    ],    "conditions": {        "all": [            {                "field": "custom_fields_17531702893847",                "operator": "present",                "value": null            }        ],        "any": []    }  }}'

In response, you'll get details about the trigger similar to this:

// Status 201 Created
{    "url": "https://{subdomain}.zendesk.com/api/v2/triggers/17532274678039.json",    "id": 17532274678039,    "title": "Triage Software Requests",    "active": true,    "updated_at": "2023-09-14T18:32:50Z",    "created_at": "2023-09-14T18:32:50Z",    "default": false,    "actions": [        {            "field": "group_id",            "value": "15609689242263"        }    ],    "conditions": {        "all": [            {                "field": "custom_fields_17531702893847",                "operator": "present",                "value": null            }        ],        "any": []    },    "description": null,    "position": 1,    "raw_title": "Triage Software Requests",    "category_id": "15590471937303"}

Now let's say your admin wants a second trigger that sends an email notification when a license is assigned to a user. To do this, you define the following:

  • A new lookup field named Assigned to with the key assigned_to on the License object that points to Users.
  • A ticket lookup relationship field that points to the License object. The field name is License assigned to and the id is 17680080658199.

Now you can create a trigger that sends an email to the user specified in the ticket's License assigned to field. In the email notification you send to the user, you can reference custom object fields and values in placeholders. For example:

curl https://{subdomain}.zendesk.com/api/v2/triggers.json \  -H "Content-Type: application/json" -X POST \  -u {email}:{password} \  -d '{  "trigger": {    "title": "Triage Software Requests",    "category_id": "15590471937303",    "actions": [        {            "field": "notification_user",            "value": [                "lookup:ticket.ticket_field_17680080658199.custom_fields.assigned_to",                "License for requested software",                "You've been assigned the following license for {{ticket.ticket_field_17531702893847}}:\n\n{{custom_object.license.custom_fields.name}}"            ]        },        {            "field": "custom_status_id",            "value": "15590402606999"        }    ],    "conditions": {        "all": [            {                "field": "custom_fields_17680080658199",                "operator": "present",                "value": null            }        ],        "any": []    }  }}'

In response, you'll get details about the trigger similar to this:

{  // Status 201 Created
    "url": "https://{subdomain}.zendesk.com/api/v2/triggers/17532274678039.json",    "id": 17532274678039,    "title": "Notify of license assignment",    "active": true,    "updated_at": "2023-09-20T14:21:48Z",    "created_at": "2023-09-20T14:21:48Z",    "default": false,    "actions": [        {            "field": "notification_user",            "value": [                "lookup:ticket.ticket_field_17680080658199.custom_fields.assigned_to",                "License for requested software",                "You've been assigned the following license for {{ticket.ticket_field_17531702893847}}:\n\n{{custom_object.license.custom_fields.name}}"            ]        },        {            "field": "custom_status_id",            "value": "15590402606999"        }    ],    "conditions": {        "all": [            {                "field": "custom_fields_17680080658199",                "operator": "present",                "value": null            }        ],        "any": []    },    "description": null,    "position": 1,    "raw_title": "Notify of license assignment",    "category_id": "15590471937303"}