Set custom fields via Smart Rules using Zapier

Introduction:

While HappyFox currently doesn't allow you to set or clear custom fields using Smart Rules directly, this can be achieved using HappyFox Webhooks and Zapier. In my example, I am trying to set a custom field 'Remarks' as 'RMA approved' if the ticket is moved to 'Open' status.

Requirements:

1. A live HappyFox account.

2. A live Zapier account (Paid or Free depending on the usage volume - Zapier pricing).

3. Some developer experience is nice to have, in case you are planning to alter the behavior.

Set up time: ~20 mins

Steps to set up:

1. Go to Manage >> Integrations >> API and set up a new API, auth code pair.

2. Go to Manage >> Ticket custom fields and create a new custom field.

3. Log into Zapier and create a new Zap.

4. In the trigger app, choose 'Webhooks by Zapier'

5. Choose 'Catch Hook' in the choose trigger step.

6. Ignore the 'Pick Off Child key' option and go to next step. When you go to test this option, you'll be given a webhook URL. Copy this URL to clipboard.

7. In HappyFox, open Manage >> Smart Rules and create a new smart rule. In the new rule, set your conditions for the smart rule which should trigger the custom field change. In the actions, choose 'Trigger Webhook'. Paste the webhook URL copied from step 6 here.

Note: If you are not seeing 'Trigger Webhook' option, go to Manage >> Integrations >> Webhooks and make sure Webhooks active is set as Yes. When Zapier prompts you, Trigger a test webhook by creating a new ticket and satisfying the smart rule conditions at this stage, to see if the webhook is received by Zapier. This is required for the following steps.

8. In Zapier for the Action app(Step 2 on the left navigation) click 'choose app' and pick 'Code by Zapier' and pick Python as the 'choose action'.

9. In the set template part under input date, give ticketid as the name of the field and pick 'Step1:Ticket Id'. In the code area paste the following code:

import requests
url = 'https://<subdomain>.happyfox.com/api/1.1/json/ticket/' + input['ticketid'] +'/staff_update/'
auth = (‘<api key>', ‘<authcode>')
payload = {'staff' : '1', 't-cf-<ticket field ID>' : ‘<value>'}
res = requests.post(url,auth=auth,data=payload)
output = [{'dummy': 'output'}]
10. Finally, replace the <placeholder> items with your account information. After this step, the set page will look like this.
11. You are now all set to set. When your smart rule conditions are met, HappyFox triggers the webhook URL, which then invokes the python script to set the custom field to a pre-determined value automatically.
  • 540
  • 03-Oct-2018
  • 2515 Views