Skip to content

fix(zammad): handle flat list response from search API#470

Open
skjnldsv wants to merge 1 commit into
psss:mainfrom
skjnldsv:fix/zammad-list-response
Open

fix(zammad): handle flat list response from search API#470
skjnldsv wants to merge 1 commit into
psss:mainfrom
skjnldsv:fix/zammad-list-response

Conversation

@skjnldsv
Copy link
Copy Markdown

Summary

Newer Zammad instances return a flat list of ticket objects from the
search endpoint instead of the {"assets": {"Ticket": {...}}} enveloppe.

Fix

Detect the response type:

  • list → build {str(id): ticket} dict directly
  • dict → existing assets.Ticket unwrap path

Both paths produce the same structure consumed by TicketsUpdated.fetch().

Traceback

Traceback (most recent call last):
  ...
  File ".../did/plugins/zammad.py", line 114, in fetch
    for _, ticket in self.parent.zammad.search(query).items():
                     ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File ".../did/plugins/zammad.py", line 63, in search
    result = self.perform_search(query)["assets"]
             ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: list indices must be integers or slices, not str

Tested against a Zammad instance runing the newer API format, confirmed working.

Newer Zammad instances return a flat list of ticket objects from the
search endpoint instead of the `{"assets": {"Ticket": {...}}}` envelope.

Handle both formats: if the response is a list, build the expected
`{id: ticket}` dict directly; otherwise fall through to the existing
assets-unwrap path.

Fixes: TypeError: list indices must be integers or slices, not str
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv
Copy link
Copy Markdown
Author

cc @come-nc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant