AlessandroSechi / zammad-go

BSD 3-Clause "New" or "Revised" License
11 stars 6 forks source link

Ticket Numbers #21

Open scheibling opened 1 month ago

scheibling commented 1 month ago

There's a bit of an issue with the Ticket object when creating tickets, namely if you try to create a ticket without manually specifying a ticket number it will let you create exactly one such ticket (which then has an empty ticket number), and all subsequent requests fail. This means You'd have to query Zammad for the highest ticket ID before creating a ticket every time (or start using very large random numbers) currently

For me at least, the intended behaviour would be to fall back to letting Zammad auto-generate the ticket numbers by adding the "omitempty" tag to the json annotation for the Ticket.Number field. Alternatively, implementing a custom serialization or "empty" check on create for the Number field and any other fields that might not be specified to let Zammad handle those with defaults

miekg commented 1 month ago

do you have a code example? I might be that we don't have an omit_empty on various fields in Ticket, but I would hope/suspect that zammad would then return an error instead

scheibling commented 1 month ago

Zammad does return an error when creating the second ticket, because it doesn't handle empty strings the same as it does a null value.

On a regular rest request to create a ticket in Zammad you'd normally exclude the "number" field in the POST request if you want Zammad to auto-generate a number for you from the existing number series.

This library currently doesn't let you do that, if you leave the Ticket.Number field empty it will send { "number": "" } in the creation request which creates a ticket with an empty ticket number and not automatically

Adding the omitempty tag to that field would exclude the number field in the marshalled json, which would then default to Zammad giving the ticket a number automatically.

This is the example API call on the Zammad site to create a ticket:

{
   "title": "Help me!",
   "group": "2nd Level",
   "customer": "david@example.com"
}

If you create a ticket object with this library:


ticket := Ticket{
      Title: "Help me!",
      GroupID: 123,
      CustomerID: 123,
}

It will serialize and be sent to Zammad like this:

{
  "id": 0,
  "group_id": 123,
   "priority_id": 0,
   "state_id": 0,
   "organization_id": 0,
   "number": "",
   "title": "Help me!",
   "owner_id": 0,
   "customer_id": 0,
   "last_contact_at": 0,
   "last_contact_agent_at": 0,
   "last_contact_customer_at": 0,
   "create_article_type_id": 0,
   "create_article_sender_id": 0,
   "article_count": 0,
   "created_by_id": 0,
   "created_at": 0,
   "updated_at": 0
}
miekg commented 1 month ago

something like #22 should fix this, haven't tested this yet against our live zammad instance.

scheibling commented 1 month ago

Thanks, looks good as far as I can see! I tested a few calls and everything seems to work as intended

Worst case, if a (future) mandatory field is set as omitempty and the user doesn't get it, they'll get an error back from Zammad and have to fill it out.

miekg commented 1 month ago

I've tested it also and pushed some more updates; you can also set an article in the ticket, just like the python client.

https://zammad-py.readthedocs.io/en/latest/readme.html (has some other good ideas, that we can use, type: "note" for example. update: type: "note" just works

miekg commented 1 week ago

closed by #22