How to set a value to text custom field based when a specific word is in the body. | Community
Skip to main content

How to set a value to text custom field based when a specific word is in the body.

  • July 26, 2021
  • 3 replies
  • 0 views

I am trying to populate the current date and time to a text custom field when a certain string is in the body of the comment. I believe we cannot set values for text custom fields using triggers. What would be the best way to do this?

This topic has been closed for replies.

3 replies

  • July 27, 2021

Hey there @Kiiro Sora, really great question:

You are absolutely correct that triggers and automations sadly don't have any actions available to fill in ticket text fields like they do with dropdown or multi-select fields, but you could fire a HTTP target as a trigger/automation action instead to update the same ticket via API (pointing to https://yoursubdomainnamehere.zendesk.com/api/v2/tickets/{{ticket.id}}.json).  In this setup, you could tell this hypothetical target to fill in a ticket's text field with the current date/time.

It's hugely important to note that we don't officially support this method due to the risk of race conditions and possible ticket collisions, but if you were still determined to have a ticket field filled in with a ticket comment, that target/trigger combo would be the way to do it.

One more important note: We've just recently announced here that these HTTP targets will be deprecated soon from the Extensions page, in favor of a newer Webhooks page located in your Admin Center.   

We don't yet have support for Support placeholders in newer webhooks, like the {{ticket.id}} in the HTTP target discussed above, but we'll be making sure that Support placeholders will be supported in these newer webhooks before HTTP targets are completely deprecated.

Thanks for reaching out Kiiro, and let us know if there's anything else we can help out with.


Nick66
  • May 7, 2022

Hi, using the API via a webhook is a nice idea. I appreciate that it isn't officially supported, but it's a good workaround. However, when I use the Bearer token with a token that I generated from the API page on the Zendesk admin, I get an error...

{
    "error": "invalid_token",
    "error_description": "The access token provided is expired, revoked, malformed or invalid for other reasons."
}

I'll keep trying, but I figured someone else might have this issue too, so worth mentioning.

Edit: Tried using both an API token (Token access) and OAuth token. Both seem to yield the same error.

Edit 2: Based on the article 'How can I authenticate API requests?' I also tried using Basic authentication, with my Zendesk email as the username and the token as the password, but this gives me the error:

{"error":"Couldn't authenticate you"}

Nick66
  • May 8, 2022

Ok, decided to use a Cloudflare worker so I could add some logic in between the Zendesk "loopback" API call. After a little bit of playing with tokens managed to get it working.

I didn't have any luck with Zendesk OAuth tokens in Cloudflare, but came across this in the API docs in relation to the regular API tokens (i.e. not OAuth):

Use the following format for the credentials:

{email_address}/token:{api_token}

Example:

jdoe@example.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

After base64-encoding the resulting string, add it to the Authorization header as follows:

Authorization: Basic amRvZUBleGFtcGxlLmNvbS90b2tlbjo2d2lJQldiR2tCTW8xbVJETXVWd2t3MUVQc05rZVVqOTVQSXoyYWt2

Here's the command that I used on Mac to Base-64 encode my token.

echo -n 'foo@bar.com/token:abc123' | base64