From e23c4bcbfdcd5c4a91b01edad0ac738d40bdc76e Mon Sep 17 00:00:00 2001 From: morph027 Date: Wed, 6 Dec 2023 10:34:07 +0100 Subject: [PATCH 1/2] adde merge tickets, fixes #85 Signed-off-by: morph027 --- freshdesk/v2/api.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/freshdesk/v2/api.py b/freshdesk/v2/api.py index f81089f..10e85bf 100644 --- a/freshdesk/v2/api.py +++ b/freshdesk/v2/api.py @@ -200,6 +200,40 @@ def filter_tickets(self, query, **kwargs): return [Ticket(**t) for t in tickets] + def merge_ticket( + self, + primary_id: int, + ticket_ids: list, + note_in_primary=None, + note_in_secondary=None, + ): + """ + Merge tickets. https://developers.freshdesk.com/api/#ticket_merge + + Args: + primary_id (int): Ticket to which conversations from secondary tickets will be merged + ticket_ids (list[int]): IDs of tickets to be merged + note_in_primary (dict): This contains the note added to the primary ticket along with + the type of the note (public/private). A default note gets added if + this is not specified in the request + note_in_secondary (dict): This contains the note added to the secondary tickets along + with the type of the note (public/private). A default note gets added if + this is not specified in the request + """ + note_in_primary = note_in_primary or {} + note_in_secondary = note_in_secondary or {} + url = "tickets/merge" + data = { + "primary_id": primary_id, + "ticket_ids": ticket_ids, + } + if note_in_primary and isinstance(dict, note_in_primary): + data.update({"note_in_primary": note_in_primary}) + if note_in_secondary and isinstance(dict, note_in_secondary): + data.update({"note_in_secondary": note_in_secondary}) + ticket = self._api._put(url, data=json.dumps(data)) + return Ticket(**ticket) + class CommentAPI(object): def __init__(self, api): From 8b8b2c9be0ca277d3c64e1cb09015c58b824854d Mon Sep 17 00:00:00 2001 From: morph027 Date: Wed, 6 Dec 2023 13:24:22 +0100 Subject: [PATCH 2/2] fix isinstance call Signed-off-by: morph027 --- freshdesk/v2/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freshdesk/v2/api.py b/freshdesk/v2/api.py index 10e85bf..7542fb4 100644 --- a/freshdesk/v2/api.py +++ b/freshdesk/v2/api.py @@ -227,9 +227,9 @@ def merge_ticket( "primary_id": primary_id, "ticket_ids": ticket_ids, } - if note_in_primary and isinstance(dict, note_in_primary): + if note_in_primary and isinstance(note_in_primary, dict): data.update({"note_in_primary": note_in_primary}) - if note_in_secondary and isinstance(dict, note_in_secondary): + if note_in_secondary and isinstance(note_in_secondary, dict): data.update({"note_in_secondary": note_in_secondary}) ticket = self._api._put(url, data=json.dumps(data)) return Ticket(**ticket)