Triggers import/export or API

Infos:

  • Used Zammad version: 6.2.0-1710170837.6e9cfa61.jammy amd64
  • Used Zammad installation type: package
  • Operating system: Debian 12
  • Browser + version: 123.0 (64-bit)

Expected behavior:

  • Have the possibility to create, OR import OR export triggers using the rails console OR the API

Actual behavior:

  • I did not find anything in these regards

Steps to reproduce the behavior:

  • Try to create Triggers automatically in a reproducible and auditable manner

As I am preparing a possible migration to Zammad, I was able to write a few scripts to call the API and add roles, organizatios and update existing groups

Since there is the need to create ~120 triggers to move incoming tickets from the generic Support group to the correct group, it would be helpful to be able to prepare the triggers beforehand on a staging instance and then move them to the production instance in a reproducible and auditable manner through the API or rails console. Also for future changes to the system.

Does anyone have a tip about where to look at, as I did not find anything in these regards

Thanks

What I found in the meantime is that I can list all triggers using

# Query all triggers
all_triggers = Trigger.all

# Iterate through the triggers and access their attributes
all_triggers.each do |trigger|
  puts "Name: #{trigger.name}, Condition: #{trigger.condition}, Perform: #{trigger.perform}, Disable Notification: #{trigger.disable_notification}, Note: #{trigger.note}, Activator: #{trigger.activator}, Execution Condition Mode: #{trigger.execution_condition_mode}, Active: #{trigger.active}"
end

This is how you can import triggers using the rails console, of course you need to make sure that the ids are valid and existing and that you set correct id for updated_by_id and created_by_id

# Create a new Trigger record
trigger = Trigger.create(
  name: "Move from Support to TEST",
  condition: {
    "ticket.state_id" => { "operator" => "is", "value" => ["1"] },
    "ticket.owner_id" => { "operator" => "is", "pre_condition" => "not_set", "value" => [], "value_completion" => "" },
    "ticket.group_id" => { "operator" => "is", "value" => ["192"], "value_completion" => "" },
    "customer.organization_id" => { "operator" => "is", "pre_condition" => "specific", "value" => ["1"], "value_completion" => "" }
  },
  perform: { "ticket.group_id" => { "value" => "105" } },
  disable_notification: true,
  note: "",
  activator: "action",
  execution_condition_mode: "selective",
  active: true,
  updated_by_id: 85,
  created_by_id: 85
)

To export them to /tmp as .json as long as the Zammad user has access to /tmp

# Export Triggers to JSON file
triggers = Trigger.all
File.open('/tmp/triggers.json', 'w') do |file|
  file.write(triggers.to_json)
end

To import them

# Import Triggers from JSON file
file_data = File.read('/tmp/triggers.json')
triggers_data = JSON.parse(file_data)

triggers_data.each do |trigger_data|
  trigger = Trigger.find_or_initialize_by(id: trigger_data['id'])
  trigger.attributes = trigger_data
  trigger.save!
end

The best is to create some example Triggers, then verify the conditions in the rails console and then replicate them.

Best,
Skip

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.