Adding new tags via Cosole (CLI)

Infos:

  • Used Zammad version: 4.1.x
  • Used Zammad installation type: package
  • Operating system: Ubuntu 20.04.02 LTS
  • Browser + version: Firefox 91.0.1 (64 Bit)

Hi @all,

I have a question. Is it possible to import tags into a new Zammad installation from a list? Via web or CLI?
I have a list of tags that I would like to use in my installation.

Thanks for your help
Kilian

Through CLI, once entered into the rails console:

irb(main):018:0> Tag::Item.all
=> #<ActiveRecord::Relation []>
irb(main):019:0> Tag::Item.lookup_by_name_and_create('TAG1')
=> #<Tag::Item id: 4, name: "TAG1", name_downcase: "tag1", created_at: "2021-08-25 06:30:06", updated_at: "2021-08-25 06:30:06">
irb(main):020:0> Tag::Item.lookup_by_name_and_create('TAG2')
=> #<Tag::Item id: 5, name: "TAG2", name_downcase: "tag2", created_at: "2021-08-25 06:30:09", updated_at: "2021-08-25 06:30:09">
irb(main):021:0> Tag::Item.all
=> #<ActiveRecord::Relation [#<Tag::Item id: 4, name: "TAG1", name_downcase: "tag1", created_at: "2021-08-25 06:30:06", updated_at: "2021-08-25 06:30:06">, #<Tag::Item id: 5, name: "TAG2", name_downcase: "tag2", created_at: "2021-08-25 06:30:09", updated_at: "2021-08-25 06:30:09">]>

And then have a look at the TAG management entry once logged as zammad admin

1 Like

Thank you that was the solution.
Is there a documentation for something like this? I have not found the commands unfortunately.

Best regards
Kilian

You’re welcome.

I’m not sure for the documentation, but there are some places in the zammad source code that worth having a look at:

You may also consider implementing your automation through the zammad api, which is certainly the most modern and long-term approach.

user@host:~$ curl -s -k --user $ZAMUSR:$ZAMPWD -H "Content-Type: application/json" -X GET http://$URL/api/v1/tag_list | jq
[
  {
    "id": 4,
    "name": "TAG1",
    "count": 0
  },
  {
    "id": 5,
    "name": "TAG2",
    "count": 0
  }
]
user@host:~$ curl -s -k --user $ZAMUSR:$ZAMPWD -H "Content-Type: application/json" -X POST --data '{"name": "TAG3-FROM-API" }' http://$URL/api/v1/tag_list | jq
{}
user@host:~$ curl -s -k --user $ZAMUSR:$ZAMPWD -H "Content-Type: application/json" -X GET http://$URL/api/v1/tag_list | jq
[
  {
    "id": 4,
    "name": "TAG1",
    "count": 0
  },
  {
    "id": 5,
    "name": "TAG2",
    "count": 0
  },
  {
    "id": 6,
    "name": "TAG3-FROM-API",
    "count": 0
  }
]

1 Like

Hi averon,

the API is of course even better. thank you very much you have helped me a lot.

Best regards
Kilian

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